QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#620271#5278. Mex and CardsAlorithmWA 0ms3752kbC++172.4kb2024-10-07 17:16:022024-10-07 17:16:25

Judging History

你现在查看的是最新测评结果

  • [2024-10-07 17:16:25]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3752kb
  • [2024-10-07 17:16:02]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using i64 = long long;
using a2 = array<i64, 2>;

struct SegTree {
#define ls (p << 1)
#define rs ((p << 1) | 1)
#define mid ((l + r) >> 1)

    int n;
    vector<i64> mex, val;

    SegTree(int N = 0) : n(N) {
        mex.resize(n << 2 | 1);
        val.resize(n << 2 | 1);
    }

    a2 query(i64 limit, int p, int l, int r) {
        if (l == r)
            if (val[p] <= limit)
                return { mex[p], val[p] };
            else
                return { limit, limit };

        if (val[ls] <= limit) {
            auto [Mex, Val] = query(limit, ls, l, mid);
            if (Val)
                return { Mex + mex[rs], val[rs] };
            return { Mex, Val };
        } else {
            auto [Mex, Val] = query(val[ls], rs, mid + 1, r);
            return { limit * (mid - l + 1ll) + Mex, Val };
        }
    }

    void update(int p, int l, int r) {
        mex[p] = mex[ls];
        val[p] = val[ls];
        if (val[ls]) {
            auto [Mex, Val] = query(val[ls], rs, mid + 1, r);
            mex[p] += Mex;
            val[p] = Val;
        }
    }

    void add(int x, int k, int p, int l, int r) {
        if (l == r) {
            val[p] += k;
            mex[p] = val[p];
            // cout << p << ' ' << l << ' ' << r << ' ' << mex[p] << ' ' << val[p] << endl;
            return;
        }

        if (x <= mid)
            add(x, k, ls, l, mid);
        if (mid + 1 <= x)
            add(x, k, rs, mid + 1, r);
        update(p, l, r);
        // cout << p << ' ' << l << ' ' << r << ' ' << mex[p] << ' ' << val[p] << endl;
    }
};

void solve() {
    int n;
    cin >> n;

    SegTree tr(n);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        tr.add(i, x, 1, 1, n);
        // cout << endl;
    }
    cout << tr.mex[1] << endl;

    int q;
    cin >> q;
    while (q--) {
        int op, x;
        cin >> op >> x;
        x++;
        if (x <= n) {
            if (op == 1)
                tr.add(x, 1, 1, 1, n);
            else
                tr.add(x, -1, 1, 1, n);
        }
        // cout << endl;
        cout << tr.mex[1] << endl;
    }
}

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

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3752kb

input:

5
2 1 3 0 2
6
1 0
1 1
2 4
1 3
2 1
2 1

output:

4
5
7
7
9
7
3

result:

ok 7 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

1
0
0

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3584kb

input:

10
3 8 1 4 10 3 10 9 7 10
20
2 5
1 4
1 2
1 4
1 3
1 3
1 0
2 8
1 5
1 4
1 0
1 3
1 8
1 6
1 4
1 1
1 5
1 9
1 6
2 7

output:

48
47
47
49
49
50
51
53
51
52
52
54
55
57
58
58
58
59
59
60
59

result:

wrong answer 1st numbers differ - expected: '14', found: '48'