52752023-04-25 09:05:51sztomiTornyokcpp11Time limit exceeded 37/100504ms145008 KiB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e6;
const int MAXK = 1e5;
const int INF = 1e9 + 7;

int magas[MAXN+1];
int indexek[MAXN];

int megoldas[MAXN+1];

vector<int> graf[MAXN];
int max_level_tav[MAXN];
bitset<MAXN> volt;

void dfs(int akt){
    max_level_tav[akt] = 1;
    volt.set(akt);
    for(int kov : graf[akt]){
        dfs(kov);
        max_level_tav[akt] = max(max_level_tav[akt], max_level_tav[kov]+1);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    int min_magas=INF, max_magas=-1;
    for(int i = 0; i < n; i++){
        cin >> magas[i];
        min_magas = min(min_magas, magas[i]);
        max_magas = max(max_magas, magas[i]);
        indexek[i] = i;
    }

    sort(indexek, indexek + n, [&magas](const int& a, const int &b){
                return magas[a] < magas[b];
         });

    // nala nagyobbak indexei
    set<int, greater<int>> aktiv_ind;
    set<int, greater<int>>::iterator it;
    for(int i = n-1; i >= 0; --i){
        it = aktiv_ind.upper_bound(indexek[i]);
        if(it != aktiv_ind.end()){
            graf[*it].push_back(indexek[i]);
        }
        aktiv_ind.insert(indexek[i]);
    }

    for(int i = 0; i < n; ++i){
        if(!volt.test(i)){
            dfs(i);
        }
    }

    megoldas[0] = 0;
    for(int i = 1; i <= n; i++){
        megoldas[i] = max(megoldas[i-1], max_level_tav[indexek[i-1]]);
    }

    magas[n] = INF;
    int kerdes;
    for(int i = 0; i < k; ++i){
        cin >> kerdes;
        int l=0, r = n, mid;
        int ki = 0;
        while(l <= r){
            mid = (l+r) / 2;
            if(magas[indexek[mid]] >= kerdes){
                ki = megoldas[mid];
                r = mid-1;
            }
            else{
                l = mid+1;
            }
        }
        cout << ki << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
base37/100
1Accepted0/019ms48704 KiB
2Time limit exceeded0/0504ms76920 KiB
3Accepted2/224ms49312 KiB
4Accepted2/220ms49684 KiB
5Accepted6/625ms49796 KiB
6Accepted6/620ms49928 KiB
7Accepted4/448ms59108 KiB
8Accepted4/472ms66624 KiB
9Accepted8/8310ms101620 KiB
10Time limit exceeded0/8462ms75696 KiB
11Time limit exceeded0/5477ms72652 KiB
12Time limit exceeded0/5469ms69596 KiB
13Accepted5/5180ms84948 KiB
14Time limit exceeded0/5402ms145008 KiB
15Time limit exceeded0/5446ms73716 KiB
16Time limit exceeded0/5476ms79108 KiB
17Time limit exceeded0/5458ms71000 KiB
18Time limit exceeded0/5477ms70180 KiB
19Time limit exceeded0/5442ms65136 KiB
20Time limit exceeded0/5458ms71264 KiB
21Time limit exceeded0/5465ms72164 KiB
22Time limit exceeded0/5458ms73996 KiB