QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#883590 | #8240. Card Game | forgotmyhandle | RE | 824ms | 235896kb | C++14 | 1.9kb | 2025-02-05 17:07:37 | 2025-02-05 17:07:46 |
Judging History
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, t2);
Merge(T[p].r, T[q1].r, T[q2].r, mid + 1, r, x, t1, t2);
}
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: 1ms
memory: 3584kb
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: 1ms
memory: 3456kb
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: 0
Accepted
time: 11ms
memory: 9932kb
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:
8 31 35 76 35 9 63 27 30 38 72 22 133 45 71 92 22 49 25 47 56 30 32 87 90 31 50 56 76 108 69 60 56 90 104 59 107 40 53 46 50 82 92 20 34 85 90 8 36 58 74 66 72 7 47 16 33 52 17 28 51 16 51 41 61 139 45 34 23 43 25 40 81 30 93 134 61 61 77 78 63 14 46 86 35 115 16 32 27 67 78 22 13 25 69 18 30 22 93 ...
result:
ok 10000 numbers
Test #4:
score: 0
Accepted
time: 681ms
memory: 177260kb
input:
300000 300000 247458 294756 90122 232046 27674 270860 146526 49400 98719 7831 68724 276111 113048 4028 56028 219364 188447 275016 284924 189020 57763 150969 208171 148849 58503 250276 15479 72273 299297 165871 20928 195677 130684 192311 298330 268331 83030 298060 35631 209221 170402 38800 53211 6839...
output:
801 801 1149 180 334 296 937 478 345 1416 747 259 179 482 664 333 836 1031 610 583 520 812 1386 528 449 1083 419 483 771 435 746 880 686 427 779 431 990 1906 622 757 332 567 91 565 226 446 240 691 414 815 382 668 1291 1059 1231 835 720 322 1403 935 281 581 613 253 959 759 325 594 115 525 559 1244 14...
result:
ok 300000 numbers
Test #5:
score: 0
Accepted
time: 824ms
memory: 235896kb
input:
300000 300000 88317 78932 58744 99868 5348 83581 56139 42780 17801 50414 28414 21205 48548 34313 71524 14868 8837 27236 54629 58491 16139 5706 88316 71645 46350 25945 1082 84228 5014 82628 65218 76940 35489 63410 37867 26565 24641 67133 72001 73332 45116 40405 20933 5650 86506 32155 15336 99468 6604...
output:
225 473 380 186 186 412 579 291 568 1146 470 200 112 836 1037 266 369 446 416 539 364 115 214 255 253 523 253 422 249 221 220 404 309 166 430 306 72 335 413 348 229 433 252 200 534 333 377 306 260 785 168 577 1221 209 515 486 380 522 320 673 273 729 157 623 864 163 119 600 309 406 631 457 833 74 391...
result:
ok 300000 numbers
Test #6:
score: -100
Runtime Error
input:
300000 300000 70 927 3159 2850 4216 1175 1731 3478 4487 3791 2903 4411 4 4333 4326 4566 248 4728 1506 80 2003 466 1903 521 942 612 734 3456 234 4658 196 4476 3751 4771 1496 894 6 130 4808 3916 4295 3632 2684 688 4588 319 2578 4407 4180 1200 2745 3243 4489 3390 3662 1466 4674 2945 4586 1156 602 3893 ...