52822023-04-25 10:04:45sztomiTornyokcpp11Time limit exceeded 42/100503ms96384 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];

int max_level_tav[MAXN]{0};
int szulo[MAXN];

struct comp{
    bool operator()(const int& a, const int& b){
        return magas[a] < magas[b];
    }
};

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, comp());

    // 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()){
            szulo[i] = *it;
        }
        else{
            szulo[i] = -1;
        }
        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++){
        if(max_level_tav[indexek[i-1]] == 0){
            max_level_tav[indexek[i-1]] = 1;
        }
        if(szulo[i-1] != -1){
            max_level_tav[szulo[i-1]] = max(max_level_tav[szulo[i-1]], max_level_tav[indexek[i-1]] + 1);
        }
        megoldas[i] = max(megoldas[i-1], max_level_tav[indexek[i-1]]);
    }

    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);

    magas[n] = INF;
    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++;
        }
    }

    for(int i = 0; i < k; i++){
        cout << valasz[i] << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base42/100
1Accepted0/03ms1848 KiB
2Time limit exceeded0/0503ms58040 KiB
3Accepted2/22ms2128 KiB
4Accepted2/23ms2440 KiB
5Accepted6/63ms2660 KiB
6Accepted6/63ms2916 KiB
7Accepted4/426ms10256 KiB
8Accepted4/448ms16528 KiB
9Accepted8/8298ms56736 KiB
10Time limit exceeded0/8451ms83176 KiB
11Time limit exceeded0/5481ms58524 KiB
12Time limit exceeded0/5472ms48832 KiB
13Accepted5/5111ms27948 KiB
14Accepted5/5308ms57284 KiB
15Time limit exceeded0/5474ms84144 KiB
16Time limit exceeded0/5435ms96384 KiB
17Time limit exceeded0/5463ms59444 KiB
18Time limit exceeded0/5458ms49712 KiB
19Time limit exceeded0/5472ms49408 KiB
20Time limit exceeded0/5462ms39560 KiB
21Time limit exceeded0/5479ms40696 KiB
22Time limit exceeded0/5458ms41404 KiB