166202025-05-07 10:14:29algoproTornyokcpp17Time limit exceeded 50/100503ms71108 KiB
// UUID: 86e7e99d-07bf-4fc9-85d4-8b25404a13ef
#include <bits/stdc++.h>
using namespace std;


int main() {
    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);
    for(int i = n; i > 0; i--){
        dp[i] = {a[i], 0};
        for(auto x : g[i]){
            dp[i][1] = max(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());
    for(int i = 2; i <= n; i++){
        dp[i][1] = max(dp[i][1], dp[i - 1][1]);
    }
    while(q--){
        array<int, 2> x;
        cin >> x[0];
        auto it = upper_bound(dp.begin(), dp.end(), x);
        it--;
        cout << (*it)[1] << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base50/100
1Accepted0/01ms316 KiB
2Time limit exceeded0/0488ms43568 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted6/61ms424 KiB
6Accepted6/62ms316 KiB
7Accepted4/437ms3052 KiB
8Accepted4/464ms5684 KiB
9Accepted8/8192ms16920 KiB
10Accepted8/8349ms43572 KiB
11Time limit exceeded0/5486ms43572 KiB
12Time limit exceeded0/5490ms41776 KiB
13Accepted5/5137ms12340 KiB
14Accepted5/5259ms28724 KiB
15Time limit exceeded0/5409ms43828 KiB
16Time limit exceeded0/5503ms35892 KiB
17Time limit exceeded0/5490ms43572 KiB
18Time limit exceeded0/5488ms42036 KiB
19Time limit exceeded0/5490ms42036 KiB
20Time limit exceeded0/5488ms69316 KiB
21Time limit exceeded0/5490ms71108 KiB
22Time limit exceeded0/5481ms66764 KiB