165512025-05-06 18:02:38algoproTornyokcpp17Wrong answer 0/100254ms63536 KiB
// UUID: 9d1d379d-77ba-482a-a1e7-941316976c66
#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);
    }
    return 0;
    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/0215ms37260 KiB
3Wrong answer0/21ms500 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/61ms316 KiB
6Wrong answer0/61ms316 KiB
7Wrong answer0/413ms2704 KiB
8Wrong answer0/423ms4928 KiB
9Wrong answer0/861ms13740 KiB
10Wrong answer0/8130ms37172 KiB
11Wrong answer0/5199ms37000 KiB
12Wrong answer0/5246ms43824 KiB
13Wrong answer0/541ms11060 KiB
14Wrong answer0/5100ms24628 KiB
15Wrong answer0/5142ms37336 KiB
16Wrong answer0/5171ms30512 KiB
17Wrong answer0/5215ms37172 KiB
18Wrong answer0/5254ms44344 KiB
19Wrong answer0/5248ms44340 KiB
20Wrong answer0/5226ms59896 KiB
21Wrong answer0/5238ms59956 KiB
22Wrong answer0/5245ms63536 KiB