52732023-04-25 08:39:56sztomiTornyokcpp11Time limit exceeded 42/100504ms160724 KiB
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> graf;
vector<int> max_level_tav;

void dfs(int akt){
    max_level_tav[akt] = 1;
    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;
    vector<int> magas(n);
    vector<int> indexek(n);
    for(int i = 0; i < n; i++){
        cin >> magas[i];
        indexek[i] = i;
    }

    sort(indexek.begin(), indexek.end(), [&magas](const int& a, const int &b){
                return magas[a] < magas[b];
         });

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

    max_level_tav.resize(n);
    for(int i = 0; i < n; i++){
        if(szulo[i] == -1){
            dfs(i);
        }
    }

    /*
    for(int i = 0; i < n; i++){
        cout << i << ": " << max_level_tav[i] << "\n";
    }
    cout << "---------------\n";
    */

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

    /*
    for(int i = 0; i <= n; i++){
        cout << i << ": " << megoldas[i] << "\n";
    }
    */

    vector<int> kerdesek(k);
    vector<int> kerdes_ind(k);
    for(int i = 0; i < k; i++){
        cin >> kerdesek[i];
        kerdes_ind[i] = i;
    }
    sort(kerdes_ind.begin(), kerdes_ind.end(), [&kerdesek](const int &a, const int &b){
            return kerdesek[a] < kerdesek[b];
         });

    vector<int> valasz(k);

    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]] = megoldas[i];
            temp_ind++;
        }
    }
    while(temp_ind < k){
        valasz[kerdes_ind[temp_ind]] = megoldas[n];
        temp_ind++;
    }

    for(int x : valasz){
        cout << x << " ";
    }
    cout << "\n";


}
SubtaskSumTestVerdictTimeMemory
base42/100
1Accepted0/03ms1892 KiB
2Time limit exceeded0/0504ms80904 KiB
3Accepted2/23ms10724 KiB
4Accepted2/23ms11192 KiB
5Accepted6/63ms11580 KiB
6Accepted6/63ms11764 KiB
7Accepted4/432ms24548 KiB
8Accepted4/452ms35304 KiB
9Accepted8/8300ms89696 KiB
10Time limit exceeded0/8456ms83916 KiB
11Time limit exceeded0/5425ms89396 KiB
12Time limit exceeded0/5456ms104116 KiB
13Accepted5/5175ms84924 KiB
14Accepted5/5374ms160060 KiB
15Time limit exceeded0/5481ms114504 KiB
16Time limit exceeded0/5481ms125200 KiB
17Time limit exceeded0/5472ms132604 KiB
18Time limit exceeded0/5446ms137096 KiB
19Time limit exceeded0/5460ms148652 KiB
20Time limit exceeded0/5504ms160724 KiB
21Time limit exceeded0/5479ms160656 KiB
22Time limit exceeded0/5476ms160712 KiB