166342025-05-07 17:14:38peti1234Tornyokcpp17Időlimit túllépés 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 << " ";
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base85/100
1Elfogadva0/025ms23860 KiB
2Elfogadva0/0360ms48432 KiB
3Elfogadva2/225ms23788 KiB
4Elfogadva2/219ms23860 KiB
5Elfogadva6/625ms23860 KiB
6Elfogadva6/619ms23844 KiB
7Elfogadva4/443ms25396 KiB
8Elfogadva4/461ms26948 KiB
9Elfogadva8/8128ms31132 KiB
10Elfogadva8/8224ms53036 KiB
11Elfogadva5/5333ms47412 KiB
12Időlimit túllépés0/5414ms51764 KiB
13Elfogadva5/587ms31772 KiB
14Elfogadva5/5150ms43152 KiB
15Elfogadva5/5222ms53556 KiB
16Elfogadva5/5307ms44080 KiB
17Elfogadva5/5356ms48428 KiB
18Időlimit túllépés0/5437ms53044 KiB
19Időlimit túllépés0/5430ms53036 KiB
20Elfogadva5/5372ms72648 KiB
21Elfogadva5/5360ms72896 KiB
22Elfogadva5/5347ms76740 KiB