QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883577#8240. Card GameforgotmyhandleWA 10ms9704kbC++141.9kb2025-02-05 17:04:452025-02-05 17:04:47

Judging History

This is the latest submission verdict.

  • [2025-02-05 17:04:47]
  • Judged
  • Verdict: WA
  • Time: 10ms
  • Memory: 9704kb
  • [2025-02-05 17:04:45]
  • Submitted

answer

#include <iostream>
using namespace std;
int n, q;
struct node {
    int l, r, tg;
} T[20000005];
int ncnt;
struct Segment_Tree {
    void Add(int &p, int q, int l, int r, int L, int R) {
        T[p = ++ncnt] = T[q];
        if (L <= l && r <= R) {
            ++T[p].tg;
            return;
        }
        int mid = (l + r) >> 1;
        if (L <= mid) 
            Add(T[p].l, T[q].l, l, mid, L, R);
        if (R > mid) 
            Add(T[p].r, T[q].r, mid + 1, r, L, R);
    }
    void Merge(int &p, int q1, int q2, int l, int r, int x, int t1, int t2) {
        p = ++ncnt, t1 += T[q1].tg, t2 += T[q2].tg;
        if (r < x) {
            T[p] = T[q1];
            T[p].tg = t1;
            return;
        }
        if (l >= x) {
            T[p] = T[q2];
            T[p].tg = t2;
            return;
        }
        int mid = (l + r) >> 1;
        Merge(T[p].l, T[q1].l, T[q2].l, l, mid, x, t1 + T[p].tg, t2 + T[q].tg);
        Merge(T[p].r, T[q1].r, T[q2].r, mid + 1, r, x, t1 + T[p].tg, t2 + T[q].tg);
    }
    int Query(int o, int l, int r, int x) {
        if (!o) 
            return 0;
        if (l == r) 
            return T[o].tg;
        int mid = (l + r) >> 1;
        if (x <= mid) 
            return T[o].tg + Query(T[o].l, l, mid, x);
        else 
            return T[o].tg + Query(T[o].r, mid + 1, r, x);
    }
} seg;
int rt[300005], ap[300005], a[300005];
int main() {
    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> a[i], ap[a[i]] = n + 1;
    for (int i = n; i; i--) {
        seg.Merge(rt[i], rt[i + 1], rt[ap[a[i]] + 1], 1, n, ap[a[i]], 0, 0);
        seg.Add(rt[i], rt[i], 1, n, i, ap[a[i]] - 1);
        ap[a[i]] = i;
    }
    int lans = 0;
    while (q--) {
        int l, r;
        cin >> l >> r;
        l ^= lans, r ^= lans;
        cout << (lans = seg.Query(rt[l], 1, n, r)) << "\n";
    }
    return 0;
}
/*
5 5
3 3 1 1 1
5 5
3 4
3 3
0 5
3 5
*/

詳細信息

Test #1:

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

input:

5 5
3 3 1 1 1
5 5
3 4
3 3
0 5
3 5

output:

1
2
1
0
1

result:

ok 5 number(s): "1 2 1 0 1"

Test #2:

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

input:

7 7
2 4 1 2 3 1 2
1 6
0 4
3 3
0 4
0 3
0 6
2 7

output:

2
1
1
1
2
3
0

result:

ok 7 numbers

Test #3:

score: -100
Wrong Answer
time: 10ms
memory: 9704kb

input:

10000 10000
160 120 157 1393 1368 911 449 735 662 698 480 730 1184 768 1291 1012 834 61 1925 642 1401 1681 441 367 1498 1215 1969 1895 857 304 400 524 1138 846 810 885 68 1737 199 90 321 1109 980 1097 1936 1482 753 1796 1787 1939 291 1201 1025 367 980 1785 1781 276 1774 777 861 967 1428 1060 1300 32...

output:

20
42
51
57
19
9
87
102
30
66
90
97
72
114
42
72
93
181
16
86
98
56
39
118
58
68
61
61
70
84
70
57
36
66
115
13
73
142
108
39
92
55
180
65
98
38
70
79
37
74
84
123
76
34
66
94
129
43
58
75
87
31
118
53
115
71
90
50
46
94
68
86
47
58
96
67
174
134
75
91
83
42
75
115
111
62
85
81
27
94
39
130
51
85
80...

result:

wrong answer 1st numbers differ - expected: '8', found: '20'