166342025-05-07 17:14:38peti1234Tornyokcpp17Time limit exceeded 85/100437ms76740 KiB
#include <bits/stdc++.h>
using namespace std;
const int c=1000005;
vector<int> g[c];
int a[c];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    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 << " ";
}
SubtaskSumTestVerdictTimeMemory
base85/100
1Accepted0/025ms23860 KiB
2Accepted0/0360ms48432 KiB
3Accepted2/225ms23788 KiB
4Accepted2/219ms23860 KiB
5Accepted6/625ms23860 KiB
6Accepted6/619ms23844 KiB
7Accepted4/443ms25396 KiB
8Accepted4/461ms26948 KiB
9Accepted8/8128ms31132 KiB
10Accepted8/8224ms53036 KiB
11Accepted5/5333ms47412 KiB
12Time limit exceeded0/5414ms51764 KiB
13Accepted5/587ms31772 KiB
14Accepted5/5150ms43152 KiB
15Accepted5/5222ms53556 KiB
16Accepted5/5307ms44080 KiB
17Accepted5/5356ms48428 KiB
18Time limit exceeded0/5437ms53044 KiB
19Time limit exceeded0/5430ms53036 KiB
20Accepted5/5372ms72648 KiB
21Accepted5/5360ms72896 KiB
22Accepted5/5347ms76740 KiB