166212025-05-07 10:15:37algoproTornyokcpp17Time limit exceeded 90/100432ms75716 KiB
// UUID: 6426ebd9-3647-4874-99ae-51665f5ee249
#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]){
            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
base90/100
1Accepted0/01ms316 KiB
2Accepted0/0358ms43824 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted6/61ms316 KiB
6Accepted6/61ms316 KiB
7Accepted4/419ms3304 KiB
8Accepted4/430ms5652 KiB
9Accepted8/892ms17064 KiB
10Accepted8/8187ms43600 KiB
11Accepted5/5314ms43572 KiB
12Accepted5/5379ms51764 KiB
13Accepted5/571ms12340 KiB
14Accepted5/5133ms28724 KiB
15Accepted5/5202ms43828 KiB
16Accepted5/5280ms36152 KiB
17Accepted5/5354ms43772 KiB
18Time limit exceeded0/5407ms52276 KiB
19Time limit exceeded0/5432ms52272 KiB
20Accepted5/5361ms71620 KiB
21Accepted5/5381ms71620 KiB
22Accepted5/5333ms75716 KiB