165602025-05-06 18:14:03algoproTornyokcpp17Wrong answer 0/100345ms124212 KiB
// UUID: 992bbc05-f106-4a2e-9596-49a1cd3caeef
#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;
    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<long long> sortedArr(n+k);
    for(int i=0;i<n;i++) sortedArr[i]=(((long long)(h[i])<<32)|i);
    for(int i=0;i<k;i++) sortedArr[n+i]=(((long long)(towerH[i])<<32)|n+i);
    //sort(sortedArr.begin(), sortedArr.end());
    int bestSoFar=0;
    vector<int> ans(k);
    for(int i=0;i<n+k;i++){
        sortedArr[i]&=0xffffffff;
        if(n<=sortedArr[i]){
            ans[sortedArr[i]-n]=bestSoFar+1;
        }
        else{
            bestSoFar=max(bestSoFar, numLess[sortedArr[i]]);
        }
    }
    for(int x : ans) cout << x << ' ';
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Wrong answer0/01ms316 KiB
2Wrong answer0/0263ms48432 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/61ms316 KiB
6Wrong answer0/61ms324 KiB
7Wrong answer0/414ms3792 KiB
8Wrong answer0/425ms6272 KiB
9Wrong answer0/874ms18504 KiB
10Wrong answer0/8172ms62940 KiB
11Wrong answer0/5238ms47156 KiB
12Wrong answer0/5298ms55860 KiB
13Wrong answer0/550ms13364 KiB
14Wrong answer0/5133ms39224 KiB
15Wrong answer0/5186ms63796 KiB
16Wrong answer0/5206ms39740 KiB
17Wrong answer0/5263ms48436 KiB
18Wrong answer0/5312ms57396 KiB
19Wrong answer0/5300ms57652 KiB
20Wrong answer0/5308ms115456 KiB
21Wrong answer0/5333ms115764 KiB
22Wrong answer0/5345ms124212 KiB