166502025-05-07 18:16:44algoproTornyokcpp17Időlimit túllépés 75/100485ms76740 KiB
// UUID: b4b33d6f-cf5d-4952-ad2b-a1cade81474e
#pragma GCC optimize("O3,unroll-loops,no-stack-protector")
#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";
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base75/100
1Elfogadva0/01ms316 KiB
2Időlimit túllépés0/0405ms44552 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva6/61ms316 KiB
6Elfogadva6/61ms480 KiB
7Elfogadva4/420ms3120 KiB
8Elfogadva4/459ms5688 KiB
9Elfogadva8/8151ms17068 KiB
10Elfogadva8/8254ms43580 KiB
11Elfogadva5/5381ms43572 KiB
12Időlimit túllépés0/5462ms51764 KiB
13Elfogadva5/581ms12596 KiB
14Elfogadva5/5148ms29100 KiB
15Elfogadva5/5266ms44084 KiB
16Elfogadva5/5333ms36660 KiB
17Elfogadva5/5395ms44588 KiB
18Időlimit túllépés0/5485ms53044 KiB
19Időlimit túllépés0/5483ms53108 KiB
20Időlimit túllépés0/5435ms72644 KiB
21Időlimit túllépés0/5423ms72900 KiB
22Elfogadva5/5395ms76740 KiB