166222025-05-07 10:22:00algoproTornyokcpp17Time limit exceeded 90/100441ms75716 KiB
// UUID: 982109f3-ee0b-477d-9282-a23a58a77e46
#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);
    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());
    for(int i = 2; i <= n; i++){
        if(dp[i][1] < dp[i - 1][1]) dp[i][1] = dp[i - 1][1];
    }
    array<int, 2> x = {0, 0};
    while(q--){
        cin >> x[0];
        auto it = upper_bound(dp.begin(), dp.end(), x);
        if(it == dp.begin()){
            cout << 0 << "\n";
            continue;
        }
        it--;
        cout << (*it)[1] << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base90/100
1Accepted0/01ms316 KiB
2Accepted0/0363ms43828 KiB
3Accepted2/21ms512 KiB
4Accepted2/21ms500 KiB
5Accepted6/61ms316 KiB
6Accepted6/61ms316 KiB
7Accepted4/418ms3244 KiB
8Accepted4/430ms5684 KiB
9Accepted8/896ms17028 KiB
10Accepted8/8180ms43648 KiB
11Accepted5/5317ms43680 KiB
12Accepted5/5398ms51672 KiB
13Accepted5/571ms12340 KiB
14Accepted5/5126ms28724 KiB
15Accepted5/5204ms43828 KiB
16Accepted5/5284ms36120 KiB
17Accepted5/5347ms43828 KiB
18Time limit exceeded0/5425ms52204 KiB
19Time limit exceeded0/5441ms52276 KiB
20Accepted5/5367ms71616 KiB
21Accepted5/5370ms71620 KiB
22Accepted5/5356ms75716 KiB