QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620170#5278. Mex and CardsMCdycWA 1ms3828kbC++203.9kb2024-10-07 16:52:452024-10-07 16:52:54

Judging History

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

  • [2024-10-07 16:52:54]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3828kb
  • [2024-10-07 16:52:45]
  • 提交

answer

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

const i64 INF = 1ll << 30;

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

    int n;
    vector<i64> tr, val, L, R;

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

    void update(int p, int l, int r)
    {
        tr[p] = tr[ls];
        val[p] = val[ls];
        L[p] = L[ls];
        R[p] = R[ls];

        if (tr[ls] == mid - l + 1 && tr[rs])
        {
            auto [len, mex, lmt] = query(R[ls], rs, mid + 1, r);
            tr[p] += len;
            val[p] += mex;
            R[p] = lmt;
        }
    }

    void add(int x, int k, int p, int l, int r)
    {
        if (l == r)
        {
            val[p] += k;
            if (val[p] == 0)
            {
                tr[p] = 0;
                L[p] = R[p] = 0;
            }
            else
            {
                tr[p] = 1;
                L[p] = R[p] = val[p];
            }
            // cout << p << ' ' << l << ' ' << r << ' ' << tr[p] << ' ' << val[p] << ' ' << L[p] << ' ' << R[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 << ' ' << tr[p] << ' ' << val[p] << ' ' << L[p] << ' ' << R[p] << endl;
    }

    a3 query(i64 limit, int p, int l, int r)
    {
        if (L[p] <= limit)
        {
            return {tr[p], val[p], R[p]};
        }
        else if (l == r)
        {
            if (tr[p])
            {
                return {1ll, limit, limit};
            }
            else
            {
                return {0ll, 0ll, 0ll};
            }
        }

        if (R[ls] <= limit)
        {
            auto [len, mex, lmt] = query(limit, ls, l, mid);
            if (len == mid - l + 1)
                return {len + tr[rs], mex + val[rs], R[rs]};
            return {len, mex, R[ls]};
        }
        else
        {
            auto [len, mex, lmt] = query(limit, rs, mid + 1, r);
            if (tr[ls] == mid - l + 1)
                return {tr[ls] + len, limit * (mid - l + 1) + mex, lmt};
            return {tr[ls], limit * (mid - l + 1), limit};
        }

        // int find_less_than(int s, int t, int x, int p, int l, int r)
        // {
        //     if (minn[p] >= x)
        //         return t + 1;
        //     if (t < l || s > r)
        //         return t + 1;

        //     int res = INF;
        //     if (s <= mid && minn[ls] < x)
        //         res = min(res, find_less_than(s, t, x, ls, l, mid));
        //     if (mid + 1 <= t && minn[rs] < x)
        //         res = min(res, find_less_than(s, t, x, rs, mid + 1, r));
        //     return res;
        // }
    }
};

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.val[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.val[1] << endl;
    }

    // while (q--)
    // {
    //     int l, r, x;
    //     cin >> l >> r >> x;
    //     cout << tr.find_less_than(x, l, r, 1, 1, n) << endl;
    // }

    // cout << "Yes\n";
}

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

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3640kb

input:

1
0
0

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

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:

14
14
14
22
22
22
22
24
24
24
24
26
26
26
26
26
26
26
26
26
26

result:

ok 21 numbers

Test #4:

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

input:

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

output:

45
44
45
44
45
45
44
44
45
46
46
45
45
43
43
42
43
44
44
44
45

result:

ok 21 numbers

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3620kb

input:

100
969 519 608 546 957 82 670 100 92 581 974 529 970 54 639 216 238 620 966 162 430 10 446 884 895 292 450 180 619 389 943 855 204 605 514 997 325 98 643 915 744 249 333 431 160 434 714 976 168 573 682 69 873 285 668 561 159 858 864 683 266 564 350 214 461 421 213 568 279 624 749 433 735 437 978 95...

output:

25678
25678
25678
25678
25687
25687
25687
25687
25682
25686
25686
25686
25686
25686
25686
25686
25686
25686
25686
25686
25685
25687
25688
25688
25688
25688
25688
25688
25688
25688
25685
25685
25685
25685
25685
25685
25689
25689
25688
25688
25688
25678
25678
25678
25678
25678
25678
25678
25678
25678
...

result:

wrong answer 1st numbers differ - expected: '4923', found: '25678'