165502025-05-06 18:02:22algoproTornyokcpp17Wrong answer 0/100145ms4608 KiB
// UUID: 251c1f8a-b2c1-40fd-ac3d-5d73c141afeb
#include <bits/stdc++.h>
using namespace std;

int n, k;
vector<int> h, towerH;
vector<int> numLess;
vector<vector<int>> nbrs;

int calcLess(int Indx){
    if(0<=numLess[Indx]) return numLess[Indx];
    int ans=0;
    for(int x : nbrs[Indx]) ans=max(ans, calcLess(x)+1);
    return numLess[Indx]=ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    h.resize(n);
    for(int& x : h) cin >> x;
    towerH.resize(k);
    for(int& x : towerH) cin >> x;
    return 0;
    stack<int> stc;
    stc.push(0);
    nbrs.resize(n+1);
    for(int i=1;i<n;i++){
        while(!stc.empty() && h[stc.top()]<h[i]) stc.pop();
        nbrs[stc.empty()?n:stc.top()].push_back(i);
        stc.push(i);
    }
    numLess.resize(n+1, -1);
    calcLess(n);
    for(int i=0;i<n;i++) calcLess(i);
    vector<array<int, 2>> sortedArr(n+k);
    for(int i=0;i<n;i++) sortedArr[i]={h[i], i};
    for(int i=0;i<k;i++) sortedArr[n+i]={towerH[i], n+i};
    sort(sortedArr.begin(), sortedArr.end());
    int bestSoFar=0;
    vector<int> ans(k);
    for(int i=0;i<n+k;i++){
        if(n<=sortedArr[i][1]){
            ans[sortedArr[i][1]-n]=bestSoFar+1;
        }
        else{
            bestSoFar=max(bestSoFar, numLess[sortedArr[i][1]]);
        }
    }
    for(int x : ans) cout << x << ' ';
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Wrong answer0/01ms316 KiB
2Wrong answer0/0120ms3892 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/61ms316 KiB
6Wrong answer0/61ms316 KiB
7Wrong answer0/48ms420 KiB
8Wrong answer0/414ms820 KiB
9Wrong answer0/846ms1844 KiB
10Wrong answer0/868ms2596 KiB
11Wrong answer0/5114ms3636 KiB
12Wrong answer0/5136ms4148 KiB
13Wrong answer0/523ms1076 KiB
14Wrong answer0/548ms2000 KiB
15Wrong answer0/571ms2780 KiB
16Wrong answer0/5100ms3128 KiB
17Wrong answer0/5122ms3720 KiB
18Wrong answer0/5144ms4600 KiB
19Wrong answer0/5145ms4600 KiB
20Wrong answer0/5125ms4608 KiB
21Wrong answer0/5126ms4600 KiB
22Wrong answer0/5128ms4608 KiB