Submission #792726

# Submission time Handle Problem Language Result Execution time Memory
792726 2023-07-25T08:20:07 Z t6twotwo Abracadabra (CEOI22_abracadabra) C++17
100 / 100
657 ms 53148 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, Q;
    cin >> N >> Q;
    vector<int> A(N);
    for (int &x : A) {
        cin >> x;
    }
    vector<int> queries(Q), ans(Q);
    vector<vector<int>> q(N + 1);
    for (int i = 0; i < Q; i++) {
        int t, p;
        cin >> t >> p;
        t = min(t, N);
        p--;
        queries[i] = p;
        if (t == 0) {
            ans[i] = A[p];
        } else {
            q[t].push_back(i);
        }
    }
    vector<int> f(N, N), stk;
    for (int i = N - 1; i >= 0; i--) {
        while (!stk.empty() && A[stk.back()] < A[i]) {
            stk.pop_back();
        }
        if (!stk.empty()) {
            f[i] = stk.back();
        }
        stk.push_back(i);
    }
    vector<int> bit(N + 1);
    auto add = [&](int p, int x) {
        for (int i = p; i <= N; i += i & -i) {
            bit[i] += x;
        }
    };
    auto sum = [&](int p) {
        int s = 0;
        for (int i = p; i; i -= i & -i) {
            s += bit[i];
        }
        return s;
    };
    vector<int> L(N + 1), R(N + 1);
    set<tuple<int, int, int>> s, t;
    for (int i = 0; i < N; i = f[i]) {
        L[A[i]] = i;
        R[A[i]] = f[i];
        s.emplace(A[i], L[A[i]], R[A[i]]);
        add(A[i], R[A[i]] - L[A[i]]);
    }
    int T = N;
    for (int i = 1; i <= N; i++) {
        if (T > N / 2) {
            while (1) {
                auto [_, l, r] = *prev(s.end());
                if (T - r + l < N / 2) {
                    break;
                }
                T -= r - l;
                s.erase(prev(s.end()));
            }
            if (T > N / 2) {
                auto [v, l, r] = *prev(s.end());
                s.erase(prev(s.end()));
                int m = r - T + N / 2;
                s.emplace(v, l, m);
                add(v, m - r);
                R[v] = m;
                for (int i = m; i < r; i = f[i]) {
                    L[A[i]] = i;
                    R[A[i]] = min(r, f[i]);
                    s.emplace(A[i], L[A[i]], R[A[i]]);
                    add(A[i], R[A[i]] - L[A[i]]);
                }
            }
        }
        for (int k : q[i]) {
            int p = queries[k];
            int l = 1, r = N;
            while (l < r) {
                int m = (l + r) / 2;
                if (sum(m) > p) {
                    r = m;
                } else {
                    l = m + 1;
                }
            }
            ans[k] = A[R[l] - sum(l) + p];
        }
    }
    for (int x : ans) {
        cout << x << "\n";
    }
    return 6/22;
}
# Verdict Execution time Memory Grader output
1 Correct 238 ms 25032 KB Output is correct
2 Correct 258 ms 23888 KB Output is correct
3 Correct 296 ms 23296 KB Output is correct
4 Correct 195 ms 22372 KB Output is correct
5 Correct 251 ms 24848 KB Output is correct
6 Correct 229 ms 24024 KB Output is correct
7 Correct 240 ms 25244 KB Output is correct
8 Correct 205 ms 23328 KB Output is correct
9 Correct 203 ms 23320 KB Output is correct
10 Correct 212 ms 22408 KB Output is correct
11 Correct 253 ms 22452 KB Output is correct
12 Correct 182 ms 20112 KB Output is correct
13 Correct 201 ms 22164 KB Output is correct
14 Correct 250 ms 23844 KB Output is correct
15 Correct 204 ms 22976 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 136 ms 17392 KB Output is correct
18 Correct 162 ms 19180 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 380 ms 46624 KB Output is correct
2 Correct 383 ms 50480 KB Output is correct
3 Correct 323 ms 40016 KB Output is correct
4 Correct 298 ms 36852 KB Output is correct
5 Correct 292 ms 37824 KB Output is correct
6 Correct 283 ms 36216 KB Output is correct
7 Correct 317 ms 41988 KB Output is correct
8 Correct 332 ms 41012 KB Output is correct
9 Correct 272 ms 36976 KB Output is correct
10 Correct 310 ms 38120 KB Output is correct
11 Correct 240 ms 31196 KB Output is correct
12 Correct 265 ms 32176 KB Output is correct
13 Correct 322 ms 37180 KB Output is correct
14 Correct 241 ms 33216 KB Output is correct
15 Correct 311 ms 38944 KB Output is correct
16 Correct 22 ms 10196 KB Output is correct
17 Correct 202 ms 42696 KB Output is correct
18 Correct 233 ms 30144 KB Output is correct
19 Correct 51 ms 14440 KB Output is correct
20 Correct 84 ms 16736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 12796 KB Output is correct
2 Correct 80 ms 13624 KB Output is correct
3 Correct 74 ms 12008 KB Output is correct
4 Correct 48 ms 8884 KB Output is correct
5 Correct 63 ms 11740 KB Output is correct
6 Correct 47 ms 9004 KB Output is correct
7 Correct 59 ms 10764 KB Output is correct
8 Correct 51 ms 9684 KB Output is correct
9 Correct 57 ms 10700 KB Output is correct
10 Correct 39 ms 7848 KB Output is correct
11 Correct 41 ms 8356 KB Output is correct
12 Correct 39 ms 7880 KB Output is correct
13 Correct 41 ms 8004 KB Output is correct
14 Correct 38 ms 8124 KB Output is correct
15 Correct 40 ms 7932 KB Output is correct
16 Correct 10 ms 5204 KB Output is correct
17 Correct 41 ms 13444 KB Output is correct
18 Correct 28 ms 7352 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 238 ms 25032 KB Output is correct
2 Correct 258 ms 23888 KB Output is correct
3 Correct 296 ms 23296 KB Output is correct
4 Correct 195 ms 22372 KB Output is correct
5 Correct 251 ms 24848 KB Output is correct
6 Correct 229 ms 24024 KB Output is correct
7 Correct 240 ms 25244 KB Output is correct
8 Correct 205 ms 23328 KB Output is correct
9 Correct 203 ms 23320 KB Output is correct
10 Correct 212 ms 22408 KB Output is correct
11 Correct 253 ms 22452 KB Output is correct
12 Correct 182 ms 20112 KB Output is correct
13 Correct 201 ms 22164 KB Output is correct
14 Correct 250 ms 23844 KB Output is correct
15 Correct 204 ms 22976 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 136 ms 17392 KB Output is correct
18 Correct 162 ms 19180 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 380 ms 46624 KB Output is correct
22 Correct 383 ms 50480 KB Output is correct
23 Correct 323 ms 40016 KB Output is correct
24 Correct 298 ms 36852 KB Output is correct
25 Correct 292 ms 37824 KB Output is correct
26 Correct 283 ms 36216 KB Output is correct
27 Correct 317 ms 41988 KB Output is correct
28 Correct 332 ms 41012 KB Output is correct
29 Correct 272 ms 36976 KB Output is correct
30 Correct 310 ms 38120 KB Output is correct
31 Correct 240 ms 31196 KB Output is correct
32 Correct 265 ms 32176 KB Output is correct
33 Correct 322 ms 37180 KB Output is correct
34 Correct 241 ms 33216 KB Output is correct
35 Correct 311 ms 38944 KB Output is correct
36 Correct 22 ms 10196 KB Output is correct
37 Correct 202 ms 42696 KB Output is correct
38 Correct 233 ms 30144 KB Output is correct
39 Correct 51 ms 14440 KB Output is correct
40 Correct 84 ms 16736 KB Output is correct
41 Correct 72 ms 12796 KB Output is correct
42 Correct 80 ms 13624 KB Output is correct
43 Correct 74 ms 12008 KB Output is correct
44 Correct 48 ms 8884 KB Output is correct
45 Correct 63 ms 11740 KB Output is correct
46 Correct 47 ms 9004 KB Output is correct
47 Correct 59 ms 10764 KB Output is correct
48 Correct 51 ms 9684 KB Output is correct
49 Correct 57 ms 10700 KB Output is correct
50 Correct 39 ms 7848 KB Output is correct
51 Correct 41 ms 8356 KB Output is correct
52 Correct 39 ms 7880 KB Output is correct
53 Correct 41 ms 8004 KB Output is correct
54 Correct 38 ms 8124 KB Output is correct
55 Correct 40 ms 7932 KB Output is correct
56 Correct 10 ms 5204 KB Output is correct
57 Correct 41 ms 13444 KB Output is correct
58 Correct 28 ms 7352 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 631 ms 52992 KB Output is correct
62 Correct 657 ms 53148 KB Output is correct
63 Correct 632 ms 49096 KB Output is correct
64 Correct 488 ms 44588 KB Output is correct
65 Correct 502 ms 46656 KB Output is correct
66 Correct 549 ms 44548 KB Output is correct
67 Correct 407 ms 43064 KB Output is correct
68 Correct 450 ms 42152 KB Output is correct
69 Correct 451 ms 43972 KB Output is correct
70 Correct 438 ms 39392 KB Output is correct
71 Correct 376 ms 40196 KB Output is correct
72 Correct 426 ms 39452 KB Output is correct
73 Correct 410 ms 39520 KB Output is correct
74 Correct 371 ms 41212 KB Output is correct
75 Correct 427 ms 40464 KB Output is correct
76 Correct 19 ms 10108 KB Output is correct
77 Correct 218 ms 44380 KB Output is correct
78 Correct 239 ms 33380 KB Output is correct
79 Correct 0 ms 320 KB Output is correct
80 Correct 1 ms 212 KB Output is correct