QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#404240 | #6330. XOR Reachable | comeintocalm# | WA | 375ms | 61384kb | C++20 | 2.7kb | 2024-05-03 16:39:58 | 2024-05-03 16:39:59 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;
const int MAXN = 1e5 + 5, N = 9999;
int n, m, K, Q;
int c[MAXN];
int lka[MAXN], lkb[MAXN];
int Rt, tot, ID;
int son[MAXN * 30][2];
vector<int> vec[MAXN * 30];
void ins (int &x, int S, int dep = 29) {
if (!x) x = ++tot;
if (dep == -1) {
vec[x].push_back (ID);
//cout << x << " " << ID << endl;
return ;
}
ins (son[x][(S >> dep) & 1], S, dep - 1);
}
struct Qry {
int d, id;
} q[MAXN];
const int cmp (const Qry t1, const Qry t2) {
return t1.d < t2.d;
}
int top;
LL *stp[MAXN * 60], sta[MAXN * 60];
LL sz[MAXN], fa[MAXN];
LL Ans = 0;
LL calc (int x) {
return (LL) sz[x] * (sz[x] - 1) / 2;
}
int get (int x) { return x == fa[x] ? x : get (fa[x]); }
void chg (LL &u, LL val) {
stp[++top] = &u, sta[top] = u;
u = val;
}
void merge (int x, int y) {
//cout << 'a';
int X = x, Y = y;
//cout << x << " " << y << endl;
x = get (x), y = get (y);
if (x == y) return ;
else {
//cout << Ans << " " << calc (x) << " " << calc (y) << endl;
chg (Ans, Ans - calc (x) - calc (y));
if (sz[x] < sz[y]) swap (x, y);
chg (fa[y], x), chg (sz[x], sz[x] + sz[y]);
//cout << X << " " << sz[x] << " " << calc (x) << " " << Ans << endl;
chg (Ans, Ans + calc (x));
//cout << Ans << endl;
}
}
void bck() {
*stp[top] = sta[top], --top;
}
void psh (int x) {
//cout << 'a';
if (!x) return ;
for (int i = 0; i < vec[x].size(); ++i)
merge (lka[vec[x][i]], lkb[vec[x][i]]);
if (son[x][0]) psh (son[x][0]);
if (son[x][1]) psh (son[x][1]);
}
int ans[MAXN];
void dfs (int x, int l, int r, int dep = 29) {
//cout << 'a';
if (l > r) return ;
if (!x || dep == -1) {
//cout << 'a';
//cout << dep << endl;
//cout << " " << l << " " << r << endl;
for (int i = l; i <= r; ++i)
ans[q[i].id] = Ans;
return ;
}
int pos = l - 1;
while (pos < r && ((q[pos + 1].d >> dep) & 1) == 0)
++pos;
int rec = top;
if ((K >> dep) & 1) {
//cout << 'a';
//if (son[x][0] == 34) cout << 'a';
psh (son[x][1]), dfs (son[x][0], l, pos, dep - 1);
while (top != rec) bck();
psh (son[x][0]), dfs (son[x][1], pos + 1, r, dep - 1);
while (top != rec) bck();
}
else {
dfs (son[x][0], l, pos, dep - 1);
dfs (son[x][1], pos + 1, r, dep - 1);
}
}
int main() {
int i,j,k;
int x, y, z;
scanf ("%d%d%d", &n, &m, &K);
for (i = 1; i <= m; ++i) {
scanf ("%d%d%d", &lka[i], &lkb[i], &c[i]), c[i] ^= K;
ID = i, ins (Rt, c[i]);
}
scanf ("%d", &Q);
for (i = 1; i <= Q; ++i)
scanf ("%d", &q[i].d), q[i].id = i;
sort (q + 1, q + Q + 1, cmp);
for (i = 1; i <= n; ++i) fa[i] = i, sz[i] = 1;
dfs (Rt, 1, Q);
for (i = 1; i <= Q; ++i)
printf ("%d\n", ans[i]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3744kb
input:
4 5 5 1 2 17 1 3 4 2 3 20 2 4 3 3 4 5 4 0 7 16 167
output:
2 6 3 0
result:
ok 4 number(s): "2 6 3 0"
Test #2:
score: 0
Accepted
time: 3ms
memory: 3892kb
input:
9 13 488888932 2 7 771479959 3 8 783850182 5 7 430673756 6 8 350738034 4 9 400768807 2 3 83653266 1 2 829786563 5 8 357613791 7 9 579696618 3 7 423191200 3 5 867380255 1 9 907715012 6 9 1033650694 8 498260055 144262908 117665696 848664012 983408133 32610599 478007408 134182829
output:
16 7 5 13 13 16 16 5
result:
ok 8 numbers
Test #3:
score: 0
Accepted
time: 317ms
memory: 54392kb
input:
446 99235 764320136 1 2 467639025 1 39 240791819 1 197 320023434 1 391 968343602 1 116 841220144 1 345 697806443 1 409 489643820 1 339 733516272 1 89 560099922 1 431 722346703 1 433 246809211 1 344 769002876 1 234 597076758 1 178 505730391 1 75 826728597 1 74 14756981 1 63 280238017 1 288 638627144 ...
output:
99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 ...
result:
ok 100000 numbers
Test #4:
score: 0
Accepted
time: 247ms
memory: 54736kb
input:
443 100000 587238331 315 322 662401332 43 315 536337643 315 404 1008807430 140 315 116993236 315 349 456757176 315 421 208121145 222 315 165949374 315 359 652820576 128 315 366321131 219 315 385302776 279 315 758612678 315 369 524221824 315 418 405097334 315 344 159069559 114 315 1020799146 36 315 4...
output:
97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 97903 ...
result:
ok 100000 numbers
Test #5:
score: 0
Accepted
time: 200ms
memory: 54388kb
input:
446 99235 319005349 63 98 45774435 98 419 537824294 55 98 970456100 98 295 177258162 98 148 503686739 98 355 952389094 98 110 672181282 98 113 718706403 98 222 193797576 79 98 367361921 8 98 82995994 13 98 401334976 98 427 695043885 98 366 595065071 98 161 581346320 98 128 792799449 98 178 566239903...
output:
99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 99235 ...
result:
ok 100000 numbers
Test #6:
score: 0
Accepted
time: 187ms
memory: 54692kb
input:
442 100000 203918091 334 408 765591331 65 334 841282977 34 334 774464729 135 334 790897433 118 334 220810832 334 383 37271884 334 357 975552850 334 424 634443624 330 334 811688196 321 334 48524877 280 334 40028159 251 334 193460453 198 334 689798118 146 334 734763167 326 334 899636923 89 334 1067215...
output:
97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 97461 ...
result:
ok 100000 numbers
Test #7:
score: 0
Accepted
time: 270ms
memory: 56928kb
input:
100000 99999 131080539 55331 77587 680598826 74630 82197 773435840 9490 88468 37670073 8680 59512 493328849 38978 96144 563550542 41963 66970 73513321 1494 85761 799508674 11271 31250 1022044318 39311 99039 1054195469 26320 50975 6951442 3560 84539 467850296 32918 83458 159835633 9576 55206 85302837...
output:
15096 14956 15004 14891 15137 14885 15410 15089 15502 15087 15083 14905 15143 15137 15104 15163 15143 15111 15090 15190 15187 15156 14992 15150 15100 15082 14919 14952 15047 15120 15117 14992 14990 15087 15411 14916 15092 15133 15139 15130 14910 15184 15132 15122 15105 15210 14939 15173 14829 15455 ...
result:
ok 100000 numbers
Test #8:
score: 0
Accepted
time: 341ms
memory: 61344kb
input:
99248 100000 880016512 9609 60188 1029518407 67457 77348 128441060 8850 51205 291062482 9624 19858 873440302 20602 31653 646044502 60977 74199 403271514 77359 98694 422310541 18100 53413 641772941 31582 84949 147530174 20254 46153 615653756 78917 86611 850029098 1309 67868 867784476 96643 98988 2712...
output:
5879363 7746507 9770252 7878863 4967006 5004278 4977178 4462464 4171192 4889527 9480939 4983900 5303714 6557680 6810967 13375644 5057196 7210193 6272443 6998946 6557952 4869510 4462624 5179208 5002020 8220896 4489581 7017776 9264220 4838591 8881657 5606801 6164119 6939146 4997590 6840650 5164401 554...
result:
ok 100000 numbers
Test #9:
score: 0
Accepted
time: 295ms
memory: 60712kb
input:
100000 99999 780251002 27269 79999 468071962 21739 82319 682546466 8544 67158 927078439 41968 89207 892254915 48895 55914 193589771 811 49765 490891662 16872 46729 638680406 17867 44058 1070155835 10241 98888 957737438 2201 46513 627847434 21108 88949 186267330 51802 94981 1008817703 20063 25385 676...
output:
851649 896751 856223 866092 859330 890327 903448 864667 873749 844234 887957 862832 833840 905858 833512 864850 890697 875940 877015 889585 919407 899670 879354 835757 889043 891332 909448 910965 855701 898062 868582 884660 898820 827552 858726 865812 887067 893299 882047 902597 880316 836660 868968...
result:
ok 100000 numbers
Test #10:
score: 0
Accepted
time: 274ms
memory: 59052kb
input:
99806 100000 506098337 11316 29606 1053169611 432 77576 188106174 60898 63565 97507616 2948 56878 759293962 57945 69338 892503621 46617 98850 666735935 8904 20788 54696907 42854 49896 442509177 55987 59613 499913803 2227 46042 620057838 1275 36485 557003410 67033 68875 81080762 22626 80910 375900469...
output:
142524 143221 141571 141415 141524 142903 143150 143834 142172 143779 142631 141438 143293 143212 143554 142975 142308 143115 143789 145039 145108 143357 142820 142972 143680 143486 142794 143012 141832 141238 143252 141992 143985 143054 143789 143443 143073 141272 143134 141352 142940 143778 143199...
result:
ok 100000 numbers
Test #11:
score: 0
Accepted
time: 331ms
memory: 61376kb
input:
100000 99999 880261730 49362 60034 719788352 49362 82351 832947612 79673 82351 727350251 79673 98801 931190441 83274 98801 44235181 21205 83274 530387154 19108 21205 173298793 19108 91835 42875759 27763 91835 658199843 27698 27763 541513285 27698 69932 660043688 51737 69932 28343715 51737 64682 7092...
output:
463133 455785 451937 457179 465888 460719 456177 451132 460492 449885 456575 457673 455205 452446 453629 450871 454195 452710 452761 454742 448762 462880 454503 450564 457018 457173 446406 455921 452926 449909 455853 452542 457657 449390 451219 455492 460180 454384 451712 451310 457955 450590 453810...
result:
ok 100000 numbers
Test #12:
score: 0
Accepted
time: 320ms
memory: 60116kb
input:
99280 100000 664494301 16664 29169 599202135 16664 23186 47757770 23186 47063 53266202 47063 85549 1072849246 63153 85549 506433067 63153 80308 580031399 51234 80308 348201803 51234 73193 964438190 73193 84836 959143019 13056 84836 425988976 13056 24417 378109570 332 24417 407996769 332 15544 127696...
output:
169861 168547 170195 167590 167947 171070 169400 169439 168358 168772 169763 168179 170227 169694 170376 170362 170270 168542 168205 170671 170992 167808 170218 169766 169488 169765 169621 169346 170434 169658 168462 167814 168089 169909 169162 169769 169559 169763 171592 170886 168176 170407 170956...
result:
ok 100000 numbers
Test #13:
score: 0
Accepted
time: 277ms
memory: 58496kb
input:
100000 99999 387919793 43583 94512 58705781 10271 43583 170607984 10271 32855 106243875 16854 32855 410273584 3517 16854 890474326 3517 30975 1001361623 20910 30975 1002711314 20910 35013 187670767 32382 35013 239178409 18343 32382 649107746 18343 98413 178223318 98413 99691 35024867 52041 99691 870...
output:
55965 57403 55280 57482 55332 57469 55577 56542 55629 55614 57389 56900 56227 55407 56343 56292 55715 55744 55868 55483 56329 56020 55483 56524 55703 57237 55332 55946 56013 55305 56717 56599 56629 57509 57456 56122 57308 56593 55645 55568 57383 55493 55754 55628 55604 55622 55635 57476 56916 55462 ...
result:
ok 100000 numbers
Test #14:
score: 0
Accepted
time: 344ms
memory: 60752kb
input:
99215 100000 802557726 18718 91317 755608910 18718 63717 531481378 30529 63717 642051004 30529 98706 599162314 42379 98706 1033145474 12300 42379 475403483 12300 12338 704395523 12338 98081 711250138 57669 98081 696479725 3890 57669 159898669 3890 64697 759770705 64697 85928 251213884 11945 85928 50...
output:
325883 325574 325225 327438 326494 328594 325193 325522 326677 325193 326907 327836 326189 325885 325339 326122 325379 327013 327616 326596 326962 324792 325751 325773 325810 326287 327825 325773 327896 326283 327310 325931 326309 326164 324663 326225 324826 325760 327847 325563 326191 325762 325419...
result:
ok 100000 numbers
Test #15:
score: 0
Accepted
time: 355ms
memory: 58520kb
input:
100000 99999 402174476 58524 93393 539162433 24909 58524 573965219 58524 88865 99051060 58524 97907 525721613 28122 58524 520563970 18857 58524 305560747 492 58524 1044154487 58524 84138 410295914 4924 58524 880315377 58524 79039 763682384 58524 88879 903645824 58524 84125 286649901 58524 98278 1032...
output:
698949966 700146910 701756916 705846378 701831845 702281503 705808806 702056656 696820446 701906778 701307426 702656328 703631341 701831845 701157628 700371451 701569611 696745785 702056656 699884991 702918765 705696096 696633801 698763036 699361300 701831845 700221753 699697936 706184571 701831845 ...
result:
ok 100000 numbers
Test #16:
score: -100
Wrong Answer
time: 375ms
memory: 61384kb
input:
99105 100000 921189055 27602 89467 871564070 73578 89467 892334196 33998 89467 730765033 42525 89467 490770744 10543 89467 48350959 23444 89467 648340211 63556 89467 691268936 37607 89467 427726217 32870 89467 435269802 72115 89467 999718290 6379 89467 905774706 15973 89467 135638767 21262 89467 507...
output:
-670174327 -670429764 -651247618 -651332991 -676302149 -668897056 -657135534 -669067373 -671962153 -661484396 -658244314 -670089193 -671281130 -660290850 -670089193 -653808171 -661910615 -652271953 -670855466 -659438192 -651162252 -666171443 -660290845 -670429766 -657050232 -661484396 -651503721 -67...
result:
wrong answer 1st numbers differ - expected: '3624792969', found: '-670174327'