Submission #230670

# Submission time Handle Problem Language Result Execution time Memory
230670 2020-05-11T01:47:44 Z arbor Cake (CEOI14_cake) C++14
100 / 100
1758 ms 15456 KB
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define lc (i << 1)
#define rc (i << 1 | 1)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 250005, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f, BSZ = 320;
int N, a, d[MN], Q;
priority_queue<pii> pq;
int t[MN * 3];

void build(int i, int l, int r) {
    if (l == r) {
        t[i] = d[l];
        return;
    }
    int m = (l + r) / 2;
    build(lc, l, m);
    build(rc, m + 1, r);
    t[i] = max(t[lc], t[rc]);
}

void upd(int i, int l, int r, int idx, int val) {
    if (l > idx || r < idx) return;
    if (l == r) {
        d[idx] = val;
        t[i] = val;
        return;
    }
    int m = (l + r) / 2;
    upd(lc, l, m, idx, val);
    upd(rc, m + 1, r, idx, val);
    t[i] = max(t[lc], t[rc]);
}

int qry(int i, int l, int r, int ql, int qr) {
    if (l > qr || r < ql) return 0;
    if (l >= ql && r <= qr) return t[i];
    int m = (l + r) / 2;
    return max(qry(lc, l, m, ql, qr), qry(rc, m + 1, r, ql, qr));
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N >> a;
    for (int i = 1; i <= N; i++) {
        cin >> d[i];
        pq.emplace(d[i], i);
    }
    build(1, 1, N);
    cin >> Q;
    for (int q = 1; q <= Q; q++) {
        char op;
        cin >> op;
        if (op == 'E') {
            int idx, rnk, val = 0;
            cin >> idx >> rnk;
            vector<pii> v;
            for (int i = 0; i < rnk - 1; i++) {
                while (d[pq.top().second] != pq.top().first) pq.pop();
                v.push_back(pq.top());
                pq.pop();
            }
            if (rnk == 1) val = N + q;
            else val = v.back().first;
            upd(1, 1, N, idx, val);
            pq.emplace(val, idx);
            for (pii p : v) {
                upd(1, 1, N, p.second, p.first + 1);
                pq.emplace(p.first + 1, p.second);
            }
        } else {
            int b;
            cin >> b;
            if (b == a) cout << 0 << '\n';
            else if (b < a) {
                int mx = qry(1, 1, N, b, a - 1);
                int l = a, r = N + 1;
                while (l < r) {
                    int m = (l + r) / 2;
                    if (qry(1, 1, N, a + 1, m) > mx) r = m;
                    else l = m + 1;
                }
                cout << l - 1 - b << '\n';
            } else {
                int mx= qry(1, 1, N, a + 1, b);
                int l = 1, r = a;
                while (l < r) {
                    int m = (l + r) / 2;
                    if (qry(1, 1, N, m, a - 1) < mx) r = m;
                    else l = m + 1;
                }
                cout << b - l << '\n';
            }
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 12 ms 512 KB Output is correct
5 Correct 26 ms 960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 566 ms 7068 KB Output is correct
2 Correct 321 ms 9052 KB Output is correct
3 Correct 362 ms 9060 KB Output is correct
4 Correct 177 ms 9056 KB Output is correct
5 Correct 582 ms 9708 KB Output is correct
6 Correct 513 ms 7468 KB Output is correct
7 Correct 381 ms 13948 KB Output is correct
8 Correct 192 ms 14048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 424 ms 4716 KB Output is correct
2 Correct 292 ms 4592 KB Output is correct
3 Correct 318 ms 4464 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 390 ms 8592 KB Output is correct
6 Correct 538 ms 8796 KB Output is correct
7 Correct 452 ms 8492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 1308 KB Output is correct
2 Correct 86 ms 1348 KB Output is correct
3 Correct 202 ms 3188 KB Output is correct
4 Correct 197 ms 3060 KB Output is correct
5 Correct 230 ms 3036 KB Output is correct
6 Correct 389 ms 5336 KB Output is correct
7 Correct 299 ms 3568 KB Output is correct
8 Correct 194 ms 8688 KB Output is correct
9 Correct 1560 ms 15456 KB Output is correct
10 Correct 772 ms 7400 KB Output is correct
11 Correct 1118 ms 10572 KB Output is correct
12 Correct 1535 ms 14396 KB Output is correct
13 Correct 1758 ms 15392 KB Output is correct