QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#53211 | #4808. Great Party | ranya | RE | 2ms | 4032kb | C++14 | 1.2kb | 2022-10-04 20:16:51 | 2022-10-04 20:16:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int read() {
char c = getchar();
int v = 0;
while (c < '0') {
c = getchar();
}
while (c >= '0') {
v = v * 10 + c - 48;
c = getchar();
}
return v;
}
const int N = 1e5 + 3, V = 1e6 + 3;
int n, m, k;
int num[2][V], a[N], bl[N];
long long now, ans[N];
struct node {
int l, r, id;
} q[N];
int cmp(node x, node y) {
if (bl[x.l] ^ bl[y.l]) return bl[x.l] < bl[y.l];
return bl[x.l] & 1 ? x.r < y.r : x.r > y.r;
}
signed main() {
n = read(), m = read();
k = n / sqrt(m);
for (int i = 1; i <= n; i++) {
a[i] = a[i - 1] ^ (read() - 1);
bl[i] = (i - 1) / k + 1;
}
for (int i = 1; i <= m; i++) {
q[i].l = read() - 1, q[i].r = read();
q[i].id = i;
}
sort(q + 1, q + 1 + m, cmp);
int l = 1, r = 0;
for (int i = 1; i <= m; i++) {
int ql = q[i].l, qr = q[i].r;
while (l < ql) now -= --num[l & 1][a[l]], l++;
while (l > ql) l--, now += num[l & 1][a[l]]++;;
while (r < qr) r++, now += num[r & 1][a[r]]++;
while (r > qr) now -= --num[r & 1][a[r]], r--;
ans[q[i].id] = 1ll * (qr - ql + 1) * (qr - ql) / 2 - now;
}
for (int i = 1; i <= m; i++) {
printf("%lld\n", ans[i]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3660kb
input:
4 5 1 2 2 4 1 2 2 3 3 4 1 3 2 4
output:
3 2 3 5 5
result:
ok 5 number(s): "3 2 3 5 5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
4 5 5 6 7 8 1 2 2 3 3 4 1 3 2 4
output:
3 3 3 6 6
result:
ok 5 number(s): "3 3 3 6 6"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3632kb
input:
10 10 3 7 3 1 6 6 10 3 3 3 9 10 5 10 3 7 5 6 5 6 9 10 3 10 1 4 6 6 1 4
output:
2 18 14 2 2 2 33 10 1 10
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 2ms
memory: 3736kb
input:
10 8 91 63 1 34 50 11 10 73 96 67 5 9 2 7 2 5 4 7 1 10 3 3 1 4 5 10
output:
15 21 10 10 55 1 10 21
result:
ok 8 numbers
Test #5:
score: 0
Accepted
time: 2ms
memory: 3764kb
input:
10 6 9 539 285 408 615 861 951 413 319 368 4 4 8 10 1 7 3 9 2 3 2 10
output:
1 6 28 28 3 45
result:
ok 6 numbers
Test #6:
score: 0
Accepted
time: 2ms
memory: 3852kb
input:
10 6 1348 7002 4687 6325 8253 5750 2464 5509 6543 8704 3 9 4 8 8 8 8 9 2 9 9 10
output:
28 15 1 3 36 3
result:
ok 6 numbers
Test #7:
score: 0
Accepted
time: 2ms
memory: 3768kb
input:
10 8 59041 28802 92255 14246 65768 79252 70656 81265 98363 85237 1 6 9 10 4 7 6 8 9 10 1 2 1 3 4 5
output:
21 3 10 6 3 3 6 3
result:
ok 8 numbers
Test #8:
score: 0
Accepted
time: 2ms
memory: 3848kb
input:
10 7 28607 249948 373828 584253 989446 308313 199311 253174 283937 133758 2 4 1 2 4 9 7 8 7 8 2 6 1 1
output:
6 3 21 3 3 15 1
result:
ok 7 numbers
Test #9:
score: 0
Accepted
time: 1ms
memory: 3700kb
input:
100 98 6 9 6 10 8 10 3 4 7 5 4 10 2 10 4 5 2 1 7 1 3 1 4 1 1 2 6 9 3 10 2 5 3 2 6 2 1 7 7 6 5 4 2 5 3 2 7 2 6 2 9 7 10 7 4 2 9 3 3 7 9 1 4 9 6 1 5 5 8 3 7 5 8 3 9 5 8 7 8 6 6 3 2 3 8 1 8 1 5 9 1 8 6 3 3 7 10 6 5 5 48 72 14 46 23 28 37 84 1 65 45 72 9 19 9 81 37 53 47 50 25 26 26 88 51 54 53 69 22 94...
output:
316 534 20 1144 2054 394 64 2596 149 10 3 1944 10 148 2598 35 169 6 28 318 605 2964 366 4571 2815 130 1220 52 160 2964 129 3040 793 1491 89 1932 227 64 77 420 332 646 267 1081 902 956 2668 2191 449 149 223 5 3763 1312 102 1221 578 2188 289 681 367 960 1 226 151 720 116 101 3348 905 132 1 88 1140 199...
result:
ok 98 numbers
Test #10:
score: 0
Accepted
time: 2ms
memory: 3724kb
input:
100 96 78 64 64 32 42 65 94 54 35 27 83 6 6 90 86 45 93 72 56 80 5 31 91 87 56 10 100 79 53 69 98 93 79 28 89 5 14 4 12 100 50 98 99 6 29 38 85 37 34 85 15 76 73 7 91 93 28 10 74 23 96 77 27 84 21 79 62 69 14 81 18 93 1 23 11 1 13 72 8 91 11 45 50 67 21 42 55 44 95 57 4 85 17 96 84 46 22 56 19 58 1 ...
output:
2761 1029 4167 3989 28 90 626 625 2614 494 942 626 253 2200 171 3389 250 4539 251 941 558 55 3308 251 1372 349 55 662 2688 737 378 66 699 136 2335 44 90 151 856 626 1270 45 1121 815 406 1477 77 228 525 1760 45 210 629 2070 66 1760 9 463 15 1220 557 591 190 699 463 28 816 1076 118 44 492 44 1942 2616...
result:
ok 96 numbers
Test #11:
score: 0
Accepted
time: 2ms
memory: 3740kb
input:
100 98 354 899 868 821 878 486 413 896 872 129 97 801 838 279 971 756 250 24 245 883 731 887 106 204 381 204 678 33 340 987 80 662 845 955 39 654 989 24 105 822 704 690 573 800 243 372 939 338 986 246 983 445 196 931 290 150 610 635 809 496 779 722 596 920 67 16 391 728 575 975 469 413 82 768 680 43...
output:
21 741 21 253 1275 325 465 703 3 276 105 495 465 3 136 1224 1652 1 66 780 253 1225 2484 55 1484 120 528 1175 1484 45 300 496 1378 3239 465 1 190 630 2850 1830 1952 325 3 1 36 1325 153 435 231 1225 406 6 153 465 28 105 351 666 1769 253 2211 1891 819 406 2345 496 1830 21 528 300 2628 10 2016 6 1710 10...
result:
ok 98 numbers
Test #12:
score: 0
Accepted
time: 2ms
memory: 3840kb
input:
100 98 4940 7560 6878 1066 6510 7648 7900 5423 1384 5142 6451 2335 6486 5411 5312 3059 1974 7844 4678 9963 926 8585 6379 1352 179 919 4870 3315 1907 8327 519 9396 1628 9268 7695 9932 9154 1056 2772 3916 4397 5712 5614 7771 2968 6540 6205 2692 6900 3920 6688 2278 7843 7293 8751 5538 2638 6424 5234 27...
output:
861 351 528 2415 21 1176 2278 78 3 45 465 903 55 1035 45 171 190 120 2145 105 3 465 28 703 3570 210 66 3081 861 561 15 1081 2145 3 3 91 378 210 15 630 1596 666 990 703 66 55 45 820 55 1431 465 4186 78 276 153 136 3 231 2556 861 666 1540 300 15 15 325 2016 1128 2415 105 2850 496 55 55 1225 1770 780 2...
result:
ok 98 numbers
Test #13:
score: 0
Accepted
time: 2ms
memory: 4032kb
input:
100 98 79873 84742 75872 96693 10191 985 31311 53705 98909 81177 17919 79656 53853 81691 50226 50507 73858 61819 29518 85453 34982 53653 93823 31917 3269 21003 95730 52976 65728 25570 21628 88764 20155 36740 90961 65470 511 72479 12397 89701 31897 5413 84398 51940 52729 43338 40696 80980 67508 12297...
output:
2850 276 210 91 1891 1081 3 2485 946 2850 10 136 465 28 136 36 3741 496 1176 55 1378 45 45 465 105 2485 3 741 465 1596 1225 136 1891 1225 1378 231 351 3081 136 861 946 2278 45 1953 171 406 6 21 703 105 3570 6 91 703 1891 4278 741 105 210 1225 990 435 3828 66 1540 2080 91 3160 66 946 351 55 28 1378 2...
result:
ok 98 numbers
Test #14:
score: -100
Runtime Error
input:
100 97 870479 594266 17979 445914 279977 701082 808468 978143 124772 925808 486496 725792 13151 914792 840639 180601 194842 81935 895414 306762 943164 688186 185644 68600 41614 718973 668908 952621 806142 891060 222118 647764 302429 649853 411693 527647 102818 427196 466555 290753 496356 16854 65968...