166512025-05-07 18:16:58algoproTornyokcpp17Time limit exceeded 90/100418ms76780 KiB
// UUID: 241e2382-40cb-46c1-b9ee-e455db62f65e
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<vector<int>> g(n + 1);
    vector<int> a(n + 1);
    stack<array<int, 2>> s;
    s.push({INT_MAX, 0});
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        while(s.top()[0] <= a[i]) s.pop();
        g[s.top()[1]].push_back(i);
        s.push({a[i], i});
    }
    vector<array<int, 2>> dp(n + 1);
    dp[0] = {INT_MAX, 0};
    for(int i = n; i > 0; i--){
        dp[i] = {a[i], 0};
        for(auto x : g[i]){
            if(dp[i][1] < dp[x][1]) dp[i][1] = dp[x][1];
        }
        dp[i][1]++;
    }
    //for(int i = 1; i <= n; i++) cout << dp[i][1] << " ";
    sort(dp.begin(), dp.end());
    vector<array<int, 2>> x(q);
    for(int i = 0; i < q; i++){
        cin >> x[i][0];
        x[i][1] = i;
    }
    vector<int> ans(q);
    sort(x.begin(), x.end());
    int maxi = 0, j = 0;
    for(int i = 0; i < q; i++){
        while(dp[j][0] <= x[i][0]){
            if(maxi < dp[j][1]) maxi = dp[j][1];
            j++; 
        }
        ans[x[i][1]] = maxi;
    }
    for(auto y : ans) cout << y << "\n";
}
SubtaskSumTestVerdictTimeMemory
base90/100
1Accepted0/01ms316 KiB
2Accepted0/0347ms44596 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms508 KiB
5Accepted6/61ms316 KiB
6Accepted6/61ms316 KiB
7Accepted4/418ms3120 KiB
8Accepted4/443ms5552 KiB
9Accepted8/8112ms16984 KiB
10Accepted8/8202ms43612 KiB
11Accepted5/5312ms43572 KiB
12Accepted5/5388ms51764 KiB
13Accepted5/568ms12596 KiB
14Accepted5/5123ms28976 KiB
15Accepted5/5222ms44152 KiB
16Accepted5/5273ms36660 KiB
17Accepted5/5333ms44596 KiB
18Time limit exceeded0/5407ms53044 KiB
19Time limit exceeded0/5418ms53044 KiB
20Accepted5/5342ms72644 KiB
21Accepted5/5344ms72900 KiB
22Accepted5/5335ms76780 KiB