52852023-04-25 11:33:54sztomiTornyokcpp11Wrong answer 41/100286ms63572 KiB
#include<bits/stdc++.h>

using namespace std;

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

int n, k;
int magas[MAXN+1];
int indexek[MAXN];

bool aktiv[MAXN]{false};
int max_hossz[MAXN];
int megoldas[MAXN];
int elso[MAXN];
int utolso[MAXN];

int unio(int bal, int kozep, int jobb){
    bool a = (bal >= 0 && aktiv[bal]);
    bool b = (jobb < n && aktiv[jobb]);
    int ret = 1;
    if(a && b){ // XOX
        int uj_ertek = max_hossz[elso[jobb]] + 1;
        int uj_elso = elso[bal];
        int uj_utolso = utolso[jobb];
        ret = uj_ertek;

        max_hossz[uj_elso] = uj_ertek;
        elso[uj_utolso] = uj_elso;
        utolso[uj_elso] = uj_utolso;
    }
    else if(a){ // XO_
        int uj_ertek = max_hossz[elso[kozep]];
        int uj_elso = elso[bal];
        int uj_utolso = utolso[kozep];
        ret = uj_ertek;

        max_hossz[uj_elso] = uj_ertek;
        elso[uj_utolso] = uj_elso;
        utolso[uj_elso] = uj_utolso;
    }
    else if(b){ // _OX
        int uj_ertek = max_hossz[elso[jobb]] + 1;
        int uj_elso = elso[kozep];
        int uj_utolso = utolso[jobb];
        ret = uj_ertek;

        max_hossz[uj_elso] = uj_ertek;
        elso[uj_utolso] = uj_elso;
        utolso[uj_elso] = uj_utolso;
    }
    return ret;
}

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

    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> magas[i];
        indexek[i] = i;
        max_hossz[i] = 1;
        elso[i] = utolso[i] = i;
    }
    sort(indexek, indexek+n, [&magas](const int &a, const int & b){
            return magas[a] < magas[b];
         });

    if(n == 1){
        int kerdes;
        for(int i = 0; i < k; i++){
            cin >> kerdes;
            cout << (magas[0] < kerdes) << " ";
        }
        return 0;
    }

    vector<int> rel_magas(n);
    for(int i = 0; i < n; i++){
        rel_magas[indexek[i]] = i;
    }

    megoldas[0] = 0;
    megoldas[1] = 1;
    int ind;
    aktiv[indexek[0]] = true;
    int mo = 1;
    for(int i = 2; i <= n; i++){
        int prev_ind = indexek[i-1]; // hova lett lerakva az elotte levo

        aktiv[prev_ind] = true;
        mo = max(mo, unio(prev_ind-1, prev_ind, prev_ind+1));
        /*
        cout << "---------------------------\n";
        cout << "i: " << i << " mo: " << mo << "\n";
        for(int j = 0; j < n; j++){
            cout << (aktiv[j] ? "X" : " ") << "\t";
        }
        cout << "\n";
        for(int j = 0; j < n; j++){
            cout << rel_magas[j] << "\t";
        }
        cout << "\n";
        for(int j = 0; j < n; j++){
            cout << elso[j] << "\t";
        }
        cout << "\n";
        for(int j = 0; j < n; j++){
            cout << utolso[j] << "\t";
        }
        cout << "\n";
        cout << "----------------------------\n";
        */
        megoldas[i] = mo;
    }

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

    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
base41/100
1Accepted0/03ms1984 KiB
2Wrong answer0/0232ms51080 KiB
3Accepted2/23ms2428 KiB
4Accepted2/23ms2668 KiB
5Accepted6/63ms2900 KiB
6Wrong answer0/63ms3108 KiB
7Wrong answer0/414ms6124 KiB
8Wrong answer0/420ms8864 KiB
9Accepted8/871ms26052 KiB
10Accepted8/8119ms37556 KiB
11Wrong answer0/5211ms51212 KiB
12Wrong answer0/5257ms60340 KiB
13Accepted5/550ms14640 KiB
14Accepted5/598ms27184 KiB
15Accepted5/5130ms38808 KiB
16Wrong answer0/5186ms44312 KiB
17Wrong answer0/5232ms53044 KiB
18Wrong answer0/5273ms62540 KiB
19Wrong answer0/5286ms62708 KiB
20Wrong answer0/5211ms62920 KiB
21Wrong answer0/5209ms63056 KiB
22Runtime error0/5170ms63572 KiB