52742023-04-25 08:56:29sztomiTornyokcpp11Time limit exceeded 37/100505ms163232 KiB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e6;
const int MAXK = 1e5;

int magas[MAXN];
int indexek[MAXN];

vector<int> graf[MAXN];
int max_level_tav[MAXN];
int valasz[MAXK]{0};
bitset<MAXN> volt;
int kerdesek[MAXK];
int kerdes_ind[MAXK];

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()
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; ++i){
        scanf("%d", &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);
        }
    }

    for(int i = 0; i < k; ++i){
        scanf("%d", &kerdesek[i]);
        kerdes_ind[i] = i;
    }
    sort(kerdes_ind, kerdes_ind+k, [&kerdesek](const int &a, const int &b){
            return kerdesek[a] < kerdesek[b];
         });


    int elozo_mo = 0;
    int akt_mo = 0;
    int temp_ind = 0;
    for(int i = 0; i < n; ++i){
        while(temp_ind < k && kerdesek[kerdes_ind[temp_ind]] <= magas[indexek[i]]){
            valasz[kerdes_ind[temp_ind]] = akt_mo;
            ++temp_ind;
        }
        elozo_mo = akt_mo;
        akt_mo = max(elozo_mo, max_level_tav[indexek[i]]);
    }
    while(temp_ind < k){
        valasz[kerdes_ind[temp_ind]] = akt_mo;
        ++temp_ind;
    }

    for(int i = 0; i < k; ++i){
        cout << valasz[i] << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base37/100
1Accepted0/019ms48824 KiB
2Time limit exceeded0/0465ms76644 KiB
3Accepted2/218ms57636 KiB
4Accepted2/225ms58112 KiB
5Accepted6/625ms58460 KiB
6Accepted6/624ms58572 KiB
7Accepted4/448ms67856 KiB
8Accepted4/467ms75804 KiB
9Accepted8/8335ms111444 KiB
10Time limit exceeded0/8451ms88508 KiB
11Time limit exceeded0/5460ms88528 KiB
12Time limit exceeded0/5456ms84356 KiB
13Accepted5/5197ms104616 KiB
14Time limit exceeded0/5414ms163232 KiB
15Time limit exceeded0/5505ms99392 KiB
16Time limit exceeded0/5465ms93296 KiB
17Time limit exceeded0/5474ms90896 KiB
18Time limit exceeded0/5474ms87132 KiB
19Time limit exceeded0/5432ms82860 KiB
20Time limit exceeded0/5456ms90488 KiB
21Time limit exceeded0/5474ms91348 KiB
22Time limit exceeded0/5474ms94028 KiB