166052025-05-06 20:44:31algoproTornyokcpp17Wrong answer 0/100433ms109108 KiB
// UUID: a70b49d6-ca50-456f-aee5-0cb04d544fb0
#pragma GCC optimize("O3,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;

int n, k;
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;
    vector<long long> sortedArr(n+k);
    vector<int> h(n+1), towerH(k);
    for(int i=0;i<n;i++){
        cin >> h[i];
        sortedArr[i]=(((long long)(h[i])<<32)|i);
    }
    for(int i=0;i<k;i++){
        cin >> towerH[i];
        sortedArr[n+i]=(((long long)(towerH[i])<<32)|n+i);
    }
    h[n]=INT_MAX;
    sort(sortedArr.begin(), sortedArr.end());
    stack<int> stc;
    stc.push(n);
    nbrs.resize(n+1);
    for(int i=0;i<n;i++){
        while(h[stc.top()]<h[i]) stc.pop();
        nbrs[stc.top()].push_back(i);
        stc.push(i);
    }
    numLess.resize(n+1, -1);
    calcLess(n);
    
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Wrong answer0/01ms316 KiB
2Wrong answer0/0303ms47664 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/61ms316 KiB
6Wrong answer0/61ms316 KiB
7Wrong answer0/417ms3664 KiB
8Wrong answer0/428ms6164 KiB
9Wrong answer0/881ms18556 KiB
10Wrong answer0/8197ms57396 KiB
11Wrong answer0/5326ms47152 KiB
12Wrong answer0/5375ms55860 KiB
13Wrong answer0/561ms13112 KiB
14Wrong answer0/5143ms36148 KiB
15Wrong answer0/5188ms57908 KiB
16Wrong answer0/5257ms39220 KiB
17Wrong answer0/5303ms47668 KiB
18Wrong answer0/5375ms56680 KiB
19Wrong answer0/5368ms56628 KiB
20Wrong answer0/5379ms101940 KiB
21Wrong answer0/5344ms102196 KiB
22Time limit exceeded0/5433ms109108 KiB