52812023-04-25 09:59:43sztomiTornyokcpp11Wrong answer 0/100252ms25772 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];

int fenwick[MAXN+1];

void update(int ind, int val){
    while(ind < MAXN){
        fenwick[ind] += val;
        ind += ind & -ind;
    }
}

int query(int r){
    int ret = 0;
    while(r){
        ret += fenwick[r];
        r -= r & -r;
    }
    return ret;
}

int query(int l, int r){
    return query(r) - query(l-1);
}

int keres_szulo(int l, int r){
    if(l == r){
        return l;
    }
    int mid = (l+r) / 2;
    int ret = -1;
    if(query(mid+1, r) > 0){
        ret = keres_szulo(mid+1, r);
    }
    else if(query(l, mid) > 0){
        ret = keres_szulo(l, mid);
    }

    return ret;
}

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

    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> magas[i];
        indexek[i] = i;
    }

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

         /*
    vector<int> rel_val(n);
    for(int i = 0; i < n; i++){
        rel_val[indexek[i]] = i;
    }
    for(int x : rel_val){
        cout << x << " ";
    }
    cout << "\n";

    int sz, l, r, mid;
    // nala nagyobbak indexei
    for(int i = n-1; i >= 0; --i){
        // elso nala kisebb index kell
        // 1 indexeles a fenwick fa miatt
        sz=-1;
        l = 1, r = indexek[i];
        while(l <= r){
            if(l == r){
                sz = l-1;
                break;
            }
            mid = (l+r) / 2;
            if(query(mid+1, r) > 0){
                l = mid+1;
            }
            else if(query(l, mid) > 0){
                r = mid;
            }
            else{
                sz = -1;
                break;
            }
        }
        if(sz != -1){
            szulo[i] = sz;
        }
        else{
            szulo[i] = -1;
        }
        update(indexek[i]+1, 1);
    }

    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
base0/100
1Wrong answer0/03ms1844 KiB
2Wrong answer0/0204ms17096 KiB
3Wrong answer0/23ms2800 KiB
4Wrong answer0/23ms3016 KiB
5Wrong answer0/63ms3192 KiB
6Wrong answer0/63ms3404 KiB
7Wrong answer0/413ms4384 KiB
8Wrong answer0/418ms5352 KiB
9Wrong answer0/863ms10112 KiB
10Wrong answer0/8104ms13296 KiB
11Wrong answer0/5180ms17212 KiB
12Wrong answer0/5224ms19700 KiB
13Wrong answer0/545ms7148 KiB
14Wrong answer0/590ms10736 KiB
15Wrong answer0/5115ms14364 KiB
16Wrong answer0/5165ms16264 KiB
17Wrong answer0/5202ms19468 KiB
18Wrong answer0/5240ms22768 KiB
19Wrong answer0/5252ms23604 KiB
20Wrong answer0/5188ms23920 KiB
21Wrong answer0/5192ms24660 KiB
22Runtime error0/5150ms25772 KiB