답안 #654035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654035 2022-10-29T15:37:39 Z Vladth11 Abracadabra (CEOI22_abracadabra) C++14
100 / 100
966 ms 113392 KB
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <algorithm>

#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "

#pragma GCC optimize("Ofast")

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;

const int bSize = 11;
const int bits = 17;
const int NMAX = 200001;
const int LIMIT = NMAX * bits;

vector <pii> qq[LIMIT + 1];
int sol[NMAX * 5];
int v[NMAX];
int poz[NMAX];
int stiva[NMAX];
int vf;
int nxt[NMAX];
pii interval[NMAX];
int aib[NMAX];

void update(int node, int x) {
    for(; node < NMAX; node += node&(-node))
        aib[node] += x;
}

int query(int node) {
    int x = 0;
    for(; node > 0; node -= node&(-node))
        x += aib[node];
    return x;
}

int cb(int k){
    int r = 0, pas = (1 << bits), sum = 0;
    while(pas){
        if(r + pas < NMAX && aib[r + pas] + sum < k){
            sum += aib[r + pas];
            r += pas;
        }
        pas /= 2;
    }
    if(sum < k)
        r++;
    return r;
}


int sz(pii x) {
    if(x.second == 0)
        return 0;
    return x.second - x.first + 1;
}

int n;

void mShuffle() {
    int cine = cb(n / 2);
    if(query(cine) == n / 2) {
        return;
    }
    int dr = interval[cine].second;
    update(cine, -sz(interval[cine]));
    int pana = query(cine - 1);
    int node = n / 2;
    node -= pana;
    interval[cine] = {poz[cine], poz[cine] + node - 1};
    update(cine, sz(interval[cine]));
    int i = v[poz[cine] + node];
    while(sz(interval[i]) == 0 && poz[i] <= dr) {
        int urm = nxt[poz[i]];
        if(urm == 0)
            urm = n + 1;
        urm = min(urm, dr + 1);
        interval[i] = {poz[i], urm - 1};
        update(i, sz(interval[i]));
        if(urm != n + 1)
            i = v[urm];
        else
            break;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int q, i;
    cin >> n >> q;
    for(i = 1; i <= n; i++) {
        cin >> v[i];
        poz[v[i]] = i;
        while(vf && v[stiva[vf]] < v[i]) {
            nxt[stiva[vf]] = i;
            vf--;
        }
        stiva[++vf] = i;
    }
    i = 1;
    while(nxt[i] != 0) {
        interval[v[i]] = {i, nxt[i] - 1};
        i = nxt[i];
    }
    interval[v[i]] = {i, n};
    for(i = 1; i <= n; i++) {
        update(i, sz(interval[i]));
    }
    for(i = 1; i <= q; i++) {
        int x, y;
        cin >> x >> y;
        x = min(x, LIMIT);
        qq[x].push_back({y, i});
    }
    for(i = 0; i <= LIMIT; i++) {
        for(auto x : qq[i]) {
            int node = x.first;
            int idx = x.second;
            int cine = cb(node);
            int pana = query(cine - 1);
            node -= pana;
            sol[idx] = v[poz[cine] + node - 1];
        }
        mShuffle();
    }
    for(i = 1; i <= q; i++) {
        cout << sol[i] << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 734 ms 101316 KB Output is correct
2 Correct 745 ms 101488 KB Output is correct
3 Correct 737 ms 100956 KB Output is correct
4 Correct 693 ms 100620 KB Output is correct
5 Correct 694 ms 102936 KB Output is correct
6 Correct 699 ms 103580 KB Output is correct
7 Correct 744 ms 103816 KB Output is correct
8 Correct 718 ms 102196 KB Output is correct
9 Correct 720 ms 101060 KB Output is correct
10 Correct 700 ms 100756 KB Output is correct
11 Correct 710 ms 101304 KB Output is correct
12 Correct 677 ms 99392 KB Output is correct
13 Correct 727 ms 100260 KB Output is correct
14 Correct 710 ms 102212 KB Output is correct
15 Correct 688 ms 100588 KB Output is correct
16 Correct 421 ms 80200 KB Output is correct
17 Correct 649 ms 99624 KB Output is correct
18 Correct 665 ms 99460 KB Output is correct
19 Correct 332 ms 80216 KB Output is correct
20 Correct 318 ms 80156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 710 ms 107164 KB Output is correct
2 Correct 697 ms 107240 KB Output is correct
3 Correct 629 ms 103092 KB Output is correct
4 Correct 687 ms 103100 KB Output is correct
5 Correct 561 ms 103632 KB Output is correct
6 Correct 644 ms 102632 KB Output is correct
7 Correct 607 ms 107176 KB Output is correct
8 Correct 716 ms 106220 KB Output is correct
9 Correct 539 ms 103376 KB Output is correct
10 Correct 672 ms 105820 KB Output is correct
11 Correct 562 ms 103096 KB Output is correct
12 Correct 663 ms 102628 KB Output is correct
13 Correct 709 ms 106008 KB Output is correct
14 Correct 539 ms 102976 KB Output is correct
15 Correct 702 ms 106104 KB Output is correct
16 Correct 276 ms 85748 KB Output is correct
17 Correct 652 ms 105932 KB Output is correct
18 Correct 575 ms 101060 KB Output is correct
19 Correct 453 ms 90164 KB Output is correct
20 Correct 453 ms 91424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 424 ms 87296 KB Output is correct
2 Correct 395 ms 86452 KB Output is correct
3 Correct 448 ms 86544 KB Output is correct
4 Correct 404 ms 86040 KB Output is correct
5 Correct 452 ms 86296 KB Output is correct
6 Correct 405 ms 86184 KB Output is correct
7 Correct 372 ms 85964 KB Output is correct
8 Correct 384 ms 85924 KB Output is correct
9 Correct 370 ms 86504 KB Output is correct
10 Correct 389 ms 86080 KB Output is correct
11 Correct 400 ms 85808 KB Output is correct
12 Correct 385 ms 86080 KB Output is correct
13 Correct 379 ms 85880 KB Output is correct
14 Correct 389 ms 86264 KB Output is correct
15 Correct 373 ms 85476 KB Output is correct
16 Correct 356 ms 82892 KB Output is correct
17 Correct 397 ms 85280 KB Output is correct
18 Correct 389 ms 84568 KB Output is correct
19 Correct 311 ms 80204 KB Output is correct
20 Correct 315 ms 80216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 734 ms 101316 KB Output is correct
2 Correct 745 ms 101488 KB Output is correct
3 Correct 737 ms 100956 KB Output is correct
4 Correct 693 ms 100620 KB Output is correct
5 Correct 694 ms 102936 KB Output is correct
6 Correct 699 ms 103580 KB Output is correct
7 Correct 744 ms 103816 KB Output is correct
8 Correct 718 ms 102196 KB Output is correct
9 Correct 720 ms 101060 KB Output is correct
10 Correct 700 ms 100756 KB Output is correct
11 Correct 710 ms 101304 KB Output is correct
12 Correct 677 ms 99392 KB Output is correct
13 Correct 727 ms 100260 KB Output is correct
14 Correct 710 ms 102212 KB Output is correct
15 Correct 688 ms 100588 KB Output is correct
16 Correct 421 ms 80200 KB Output is correct
17 Correct 649 ms 99624 KB Output is correct
18 Correct 665 ms 99460 KB Output is correct
19 Correct 332 ms 80216 KB Output is correct
20 Correct 318 ms 80156 KB Output is correct
21 Correct 710 ms 107164 KB Output is correct
22 Correct 697 ms 107240 KB Output is correct
23 Correct 629 ms 103092 KB Output is correct
24 Correct 687 ms 103100 KB Output is correct
25 Correct 561 ms 103632 KB Output is correct
26 Correct 644 ms 102632 KB Output is correct
27 Correct 607 ms 107176 KB Output is correct
28 Correct 716 ms 106220 KB Output is correct
29 Correct 539 ms 103376 KB Output is correct
30 Correct 672 ms 105820 KB Output is correct
31 Correct 562 ms 103096 KB Output is correct
32 Correct 663 ms 102628 KB Output is correct
33 Correct 709 ms 106008 KB Output is correct
34 Correct 539 ms 102976 KB Output is correct
35 Correct 702 ms 106104 KB Output is correct
36 Correct 276 ms 85748 KB Output is correct
37 Correct 652 ms 105932 KB Output is correct
38 Correct 575 ms 101060 KB Output is correct
39 Correct 453 ms 90164 KB Output is correct
40 Correct 453 ms 91424 KB Output is correct
41 Correct 424 ms 87296 KB Output is correct
42 Correct 395 ms 86452 KB Output is correct
43 Correct 448 ms 86544 KB Output is correct
44 Correct 404 ms 86040 KB Output is correct
45 Correct 452 ms 86296 KB Output is correct
46 Correct 405 ms 86184 KB Output is correct
47 Correct 372 ms 85964 KB Output is correct
48 Correct 384 ms 85924 KB Output is correct
49 Correct 370 ms 86504 KB Output is correct
50 Correct 389 ms 86080 KB Output is correct
51 Correct 400 ms 85808 KB Output is correct
52 Correct 385 ms 86080 KB Output is correct
53 Correct 379 ms 85880 KB Output is correct
54 Correct 389 ms 86264 KB Output is correct
55 Correct 373 ms 85476 KB Output is correct
56 Correct 356 ms 82892 KB Output is correct
57 Correct 397 ms 85280 KB Output is correct
58 Correct 389 ms 84568 KB Output is correct
59 Correct 311 ms 80204 KB Output is correct
60 Correct 315 ms 80216 KB Output is correct
61 Correct 966 ms 113392 KB Output is correct
62 Correct 902 ms 112052 KB Output is correct
63 Correct 937 ms 111268 KB Output is correct
64 Correct 796 ms 111172 KB Output is correct
65 Correct 773 ms 112000 KB Output is correct
66 Correct 860 ms 110892 KB Output is correct
67 Correct 653 ms 110084 KB Output is correct
68 Correct 768 ms 109004 KB Output is correct
69 Correct 714 ms 111132 KB Output is correct
70 Correct 736 ms 107908 KB Output is correct
71 Correct 587 ms 109952 KB Output is correct
72 Correct 731 ms 108376 KB Output is correct
73 Correct 685 ms 109312 KB Output is correct
74 Correct 630 ms 110284 KB Output is correct
75 Correct 725 ms 109388 KB Output is correct
76 Correct 271 ms 85324 KB Output is correct
77 Correct 730 ms 105064 KB Output is correct
78 Correct 659 ms 103328 KB Output is correct
79 Correct 309 ms 80220 KB Output is correct
80 Correct 310 ms 80216 KB Output is correct