QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#93384 | #21529. 动态树(简单版) | Appleblue17# | 0 | 188ms | 5828kb | C++14 | 1.8kb | 2023-03-31 18:32:52 | 2023-03-31 18:32:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ls(x) t[x].s[0]
#define rs(x) t[x].s[1]
const int N=1e5+5,INF=1e9;
struct tree{
int fa,s[2],val;
bool rev;
}t[N];
int n,m;
int a[N];
bool nroot(int x){
int fa=t[x].fa;
return ls(fa)==x || rs(fa)==x;
}
void down(int x){
t[x].rev^=1;
swap(ls(x),rs(x));
}
void pushdown(int x){
if(t[x].rev){
down(ls(x)),down(rs(x));
t[x].rev=0;
}
}
void update(int x){
t[x].val=t[ls(x)].val^t[rs(x)].val^a[x];
}
void rotate(int x){
int y=t[x].fa,z=t[y].fa;
pushdown(y),pushdown(x);
int ky=(rs(y)==x),kz=(rs(z)==y);
if(nroot(y)) t[z].s[kz]=x;
t[x].fa=z;
t[y].s[ky]=t[x].s[ky^1],t[t[x].s[ky^1]].fa=y;
t[x].s[ky^1]=y,t[y].fa=x;
update(y),update(x);
}
void splay(int x){
while(nroot(x)){
int y=t[x].fa,z=t[y].fa;
if(nroot(y))
(ls(z)==y)^(ls(y)==x)?rotate(x):rotate(y);
rotate(x);
}
}
void access(int x){
int y=0;
while(x){
splay(x);
pushdown(x);
rs(x)=y;
update(x);
y=x,x=t[x].fa;
}
}
void makeroot(int x){
access(x);
splay(x);
down(x);
}
int findroot(int x){
access(x);
splay(x);
while(ls(x)) pushdown(x),x=ls(x);
splay(x);
return x;
}
bool split(int x,int y){
makeroot(x);
if(findroot(y)!=x) return 0;
access(y);
splay(y);
return 1;
}
bool link(int x,int y){
makeroot(x);
if(findroot(y)==x) return 0;
t[x].fa=y;
return 1;
}
bool cut(int x,int y){
makeroot(x);
if(findroot(y)!=x || t[y].fa!=x || ls(y)) return 0;
t[y].fa=ls(x)=0;
return 1;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=m;i++){
int opt,x,y;
scanf("%d%d%d",&opt,&x,&y);
if(opt==0){
split(x,y);
printf("%d\n",t[y].val);
}
else if(opt==1) link(x,y);
else if(opt==2) cut(x,y);
else splay(x),a[x]=y;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3628kb
input:
1107 4572 234284072 388981847 391448440 477366271 186930123 127662721 932242109 729840760 723502273 878156702 139426149 109192182 895711735 300412478 644823004 751154835 198812322 989657237 667888533 708218412 411100292 639169500 41236867 919203199 712987474 102870210 402909302 646634540 248335431 9...
output:
829684376 280803459 605406589 536116374 950023175 610713 364901393 322277998 573714672 388539896 813936619 205398734 176783586 212543141 460505304 653312728 58643488 90887342 673738509 101181523 439574418 991304367 668497001 797149734 937094083 169101952 196356745 467136992 196242861 873309621 90916...
result:
wrong answer 1st numbers differ - expected: '-1', found: '829684376'
Test #2:
score: 0
Wrong Answer
time: 13ms
memory: 3592kb
input:
1478 22168 569881340 405035091 712551926 875554826 406645854 501242919 392949365 237044138 991917769 860919318 602666767 824537289 108866113 139591547 894475719 715734731 605755553 104022820 783400168 675196243 810628270 544549126 785362764 761421196 242193695 758505676 432747106 153822404 399249378...
output:
977856141 185516938 725972333 407690994 452378270 701784606 510618797 799597642 969591581 355207629 230548304 915345315 981864190 208284896 825913416 169802073 6591632 383910838 726878213 196851557 203770052 4918467 878225659 161359147 300077275 544518082 751171000 575674371 78392800 671154055 16757...
result:
wrong answer 1st numbers differ - expected: '-1', found: '977856141'
Test #3:
score: 0
Wrong Answer
time: 9ms
memory: 5828kb
input:
720 11779 407324044 416057248 215358620 397121163 266598227 672056288 355038763 181861594 133030450 600486797 355994904 811704323 150048063 448794624 613007406 711725050 320509098 8205562 915133242 916173863 732977813 545177862 220442466 670371541 485288754 64702329 364293219 825915255 108377643 463...
output:
449036533 164016703 347252212 610562298 565537653 22590761 565537653 265994078 150048063 410074339 817349075 721101693 632045231 10672192 186064126 266598227 647360744 53915715 301884452 252103265 518141723 960096886 86950100 802513993 521579966 317155216 920464589 179618319 29967651 784278112 73181...
result:
wrong answer 1st numbers differ - expected: '-1', found: '449036533'
Test #4:
score: 0
Wrong Answer
time: 9ms
memory: 3572kb
input:
152 12209 691802886 215953826 702694628 981148343 975092377 201414321 739162800 21034610 849623247 174894124 308642547 863937500 45592629 757330862 742460999 305369753 932608714 856818299 619604710 74448671 893694992 867421355 443563472 437930232 428483966 96399062 384039387 462514529 756617956 5077...
output:
587046287 382192817 587046287 267354077 130726882 763505686 446650672 428483966 596123709 119070099 847621328 119070099 340484710 196215785 901097307 220790552 74448671 738330184 96399062 313100922 823695082 631459582 932608714 867117836 937317351 763505686 937317351 211324688 757330862 778275296 47...
result:
wrong answer 1st numbers differ - expected: '-1', found: '587046287'
Test #5:
score: 0
Wrong Answer
time: 19ms
memory: 3808kb
input:
1318 28124 943679982 599490657 14188757 119556929 88798936 61758796 922635692 247956744 77588643 228621429 202899979 544372814 419025104 50246858 364847087 231889637 901747480 923895179 122012732 194794597 617348787 758367265 874514156 205729541 236090640 244220088 523285104 684687814 548533722 3745...
output:
909868659 412776849 347155210 834384083 581651057 506242300 746460880 603175243 214971893 341837888 37411648 282017202 43857023 710194357 121374928 603869907 522689055 521425722 614659837 419025104 810968677 208506580 62339888 984033626 787369380 217413440 160471636 994134021 646299190 296065489 311...
result:
wrong answer 1st numbers differ - expected: '-1', found: '909868659'
Test #6:
score: 0
Wrong Answer
time: 10ms
memory: 5604kb
input:
1480 13659 273091642 808945296 126909509 426498595 492288255 110231631 618200926 68848092 665081898 648499844 420071326 268296562 743750189 186575204 243086966 64901921 391261005 789769656 991716058 783849739 765280282 479547496 414236979 290401751 562020126 50771452 972287665 845368884 626840962 93...
output:
277368671 760514273 148466617 283610086 890278492 501561758 461326839 551811463 650627623 515282934 306674710 331845764 176867165 196407974 478550161 204198156 596086719 749883983 903563106 692981656 867257400 308343559 436709371 65459912 341466014 819553085 571117826 317022695 140459493 312760929 6...
result:
wrong answer 1st numbers differ - expected: '-1', found: '277368671'
Test #7:
score: 0
Wrong Answer
time: 11ms
memory: 3616kb
input:
356 22139 431594498 480475890 373890370 228894305 640208283 595505266 344572785 806115258 525318212 7434316 670399747 732635286 366145994 719043994 889163353 481316643 334053518 322709687 488052698 271041133 556891981 503463278 570978111 418427570 706300514 701112253 465872167 343854348 10796679 693...
output:
268821729 896321284 418427570 185886809 601299083 10207704 839108055 20141052 207673993 338512544 719043994 633266060 563660852 177489666 413957599 952234106 665845301 36961687 57817801 289688218 637006418 214869283 172318898 673820878 54222527 431594498 295314925 601299083 360162152 637006418 59545...
result:
wrong answer 1st numbers differ - expected: '-1', found: '268821729'
Test #8:
score: 0
Wrong Answer
time: 7ms
memory: 3612kb
input:
50 11882 228789343 494106370 464015946 208607989 30612082 935090584 266792064 262927962 349871422 77246250 635002760 18143685 193705091 20037444 532253744 307000673 863700107 9612369 178632626 822516422 896134450 284228663 273573982 285506358 188837597 915857315 544342920 240006709 233771383 5753795...
output:
544342920 93631625 635002760 189660198 228789343 326796181 559846987 559846987 9612369 396754936 698363608 233771383 240006709 154841328 635002760 670051466 228789343 284228663 273573982 19222578 30612082 805018601 635002760 228789343 188941063 496723761 896134450 985713324 580651259 221175476 50061...
result:
wrong answer 1st numbers differ - expected: '-1', found: '544342920'
Test #9:
score: 0
Wrong Answer
time: 0ms
memory: 3596kb
input:
285 3352 582038534 874354618 806726310 653674385 772297772 295186193 603563610 369069656 585686174 161390241 223515382 798993530 34839848 597858415 632305417 284461915 396182782 530803870 966531980 290709637 319172042 322032367 551133433 955737140 820397047 398986914 822982335 590004131 622683184 21...
output:
158991364 822982335 966531980 603563610 223951868 396182782 874354618 462010259 7676935 864374903 159052287 690727462 959792443 850508577 951602355 325675248 850508577 951602355 200788425 78763114 284461915 214008680 615643448 101145129 983846416 782669842 711352116 978334626 201221888 112742012 171...
result:
wrong answer 1st numbers differ - expected: '-1', found: '158991364'
Test #10:
score: 0
Wrong Answer
time: 15ms
memory: 3580kb
input:
1166 23009 121814457 856493653 192559916 211488994 266914699 874209553 409596930 521761274 171258686 488998014 847143010 758487957 241689123 177868187 498361258 531899010 554998825 600016801 931216265 42371861 882290673 500897222 303856950 267299623 856437526 280941209 498838974 461656089 150317958 ...
output:
139623646 411074707 531079933 873204514 265974250 980328378 784000695 770002618 301893666 120721243 541078853 759567169 879977815 425500170 900095714 365005552 877366057 101829821 47603536 33234135 453611265 315196528 211903815 95402627 340256872 473560508 326040829 778309939 910310681 920791662 350...
result:
wrong answer 1st numbers differ - expected: '-1', found: '139623646'
Test #11:
score: 0
Wrong Answer
time: 106ms
memory: 4060kb
input:
12141 173689 883175862 113587309 767153473 63975437 781113122 597898346 57194917 443752894 823881866 755317463 258127039 140087455 586957338 861574464 278039976 554788225 330807907 515220000 65153632 15145921 65920285 567738421 703565961 900932465 942403662 989985109 504981988 365887866 901807269 96...
output:
205927311 246910638 281480631 269809243 781690372 950987578 795168787 368183053 630371934 1054486961 1021757717 858558127 164464388 1022496619 450508741 110947610 382489852 165979918 540041007 123321689 1017540547 819371948 476090321 343101716 893402072 147828785 158172286 709216864 965434582 617574...
result:
wrong answer 40th numbers differ - expected: '-1', found: '863721158'
Test #12:
score: 0
Wrong Answer
time: 188ms
memory: 3844kb
input:
7752 250830 597631773 176661818 485156227 625568802 597294590 597435325 857348404 817085090 592523342 8614896 28048251 874404339 485657157 744874559 357367483 825719014 146803400 302383110 309083585 192999319 546762230 544643234 678653429 996556689 849883582 508400456 948668416 371621752 382613848 1...
output:
1050456831 419222368 488997989 336653449 195501599 327111052 434050715 767026564 441213261 790612651 901483462 506139160 932029560 918888522 1017140297 783288126 734884866 510970433 708293187 581833128 1048858256 226770859 994691624 143480183 509282192 150260487 772699110 195486339 1062932224 931947...
result:
wrong answer 83rd numbers differ - expected: '-1', found: '904852108'
Test #13:
score: 0
Wrong Answer
time: 78ms
memory: 3996kb
input:
11097 120973 718385601 339533874 783190518 128303612 702689502 616478192 506735841 436109766 384473588 700034175 273821837 669150027 365238310 423587058 491529666 864149457 180078920 426454885 204104900 172286883 44243149 820224797 375205789 37076769 485913472 827308047 324202282 784645010 605128383...
output:
16642499 866928015 491290382 20175087 849017793 957892935 442273857 952700538 730567793 379615236 929938784 662388043 605186702 436406070 461711891 365621147 232060390 442651249 61302453 980869144 549001283 728452617 229415233 842082189 865820428 944724656 754940323 401832781 807708171 985620155 100...
result:
wrong answer 14th numbers differ - expected: '-1', found: '436406070'
Test #14:
score: 0
Wrong Answer
time: 19ms
memory: 5616kb
input:
12431 43068 32882151 121154219 299411874 283222799 337460974 218845250 713830636 148790236 720001343 301205091 440770942 40757843 968133429 923228052 289604734 736186667 587661347 708981435 813775951 874625904 567310343 442698414 997073675 253786372 940362862 304346555 655143795 383344997 990964675 ...
output:
583558767 133165779 465063143 111744948 455743527 910312083 825849662 158538491 202894550 102250747 761136324 146829994 756230766 538860727 760975880 873114775 153688903 13337457 993717516 147625031 113483680 76450685 96382435 305884796 567401501 736291028 910464689 34654090 811998591 724781492 4262...
result:
wrong answer 1st numbers differ - expected: '-1', found: '583558767'
Test #15:
score: 0
Wrong Answer
time: 49ms
memory: 3692kb
input:
3569 85355 340989274 973202648 19247282 372176232 424173632 284102222 245830630 76475251 210858782 148008017 411397336 319636788 743115436 301534714 718210948 378595413 108907563 232493902 73794699 941059411 454810198 266083392 313520643 505260936 551350077 898046823 922969746 326259168 864335128 98...
output:
1038885819 513687116 783996476 474637399 968721968 98519686 1066278525 386833047 925192817 163550927 699543770 866728130 359476524 708176528 932361529 274911950 295804743 1049458785 1039689933 531947647 438945604 215009755 926738759 846516082 731835150 807650956 1002936902 314768825 826270779 806937...
result:
wrong answer 95th numbers differ - expected: '-1', found: '410690221'
Test #16:
score: 0
Wrong Answer
time: 142ms
memory: 3980kb
input:
8784 197628 236997472 828403196 555774219 209146695 253908918 61752823 460934705 127206200 950931157 904539626 559632554 637355378 154635658 923777011 445506141 558026378 363092290 420469819 26314289 345860659 453597653 870312681 830583024 629506845 264093034 191518281 406456617 458631008 21362144 7...
output:
591639787 421153822 29456765 322502311 482720930 847568115 906836675 551839663 137001206 931685400 609875210 939567620 656781528 750701676 281220702 826797240 267924607 1051164236 65645971 810385756 62567794 787504679 320608356 75272244 263215496 275942803 519968401 31334678 394381072 359367268 1024...
result:
wrong answer 116th numbers differ - expected: '-1', found: '1055101392'
Test #17:
score: 0
Wrong Answer
time: 124ms
memory: 5752kb
input:
12752 192017 732940391 996566657 646454429 744251174 63138814 179176243 284614360 952508860 453683567 308145294 446610428 622135210 87362818 430538092 168876272 217184978 660711366 578054685 287396340 33037653 390046707 68434008 534397884 708822780 949153297 380706604 402596156 453673915 280396532 1...
output:
551943332 186846837 794230633 477974123 616325420 56425310 486584270 381019607 840579445 193636645 124027339 484162574 10628006 974638964 778469647 500775157 785097108 475942864 621150115 423933377 73151766 399275589 707925405 57047553 919117332 643274700 912752747 452822303 714617274 628218997 7654...
result:
wrong answer 70th numbers differ - expected: '-1', found: '673152857'
Test #18:
score: 0
Wrong Answer
time: 121ms
memory: 3752kb
input:
7858 153287 293289490 588964112 217688247 620592747 422433255 257999041 241627372 235576742 791977172 224751651 588263307 173945591 213477227 594399068 54404444 422943469 9418343 714814000 179975901 999368692 518206286 869347173 458616660 728377002 724658548 50884538 715752571 642040443 170785705 65...
output:
677271913 446520805 215358948 58714512 1052617315 693273125 286561190 188899840 245944586 375644962 183197494 37146407 688673115 62568106 832260561 233090786 975654971 936035752 675624045 422237992 891522187 106678894 828401148 199927404 9619696 414466080 715853109 985606241 680298514 720769961 3143...
result:
wrong answer 243rd numbers differ - expected: '-1', found: '671115968'
Test #19:
score: 0
Wrong Answer
time: 91ms
memory: 3764kb
input:
4529 135866 501087624 220268341 80802717 228455303 801802052 257083126 236800464 258533444 951300442 282155790 647175433 352367278 61151871 183837977 196166101 734996913 18605037 996804531 119099272 834963735 235477918 732059314 722206859 403838549 609425799 164049011 780668781 359667773 794323212 8...
output:
550087483 514892585 287161104 967100808 1008510070 110481808 132471835 305350555 719307232 335814434 614994292 332216949 677852515 669125688 50300393 184354888 568863777 13219134 610902912 419889452 935211758 330759620 654732323 598529392 752308878 433329881 846394627 957068408 353938094 84213526 42...
result:
wrong answer 55th numbers differ - expected: '-1', found: '603237805'
Test #20:
score: 0
Wrong Answer
time: 107ms
memory: 3728kb
input:
9851 170182 633242875 976652177 677894597 46060529 207648941 397996028 499801060 808417663 957948925 568024571 224469034 664929538 245866813 510612401 80371256 215382485 745756821 499898703 887314964 45070813 482812731 51500757 45659822 555237038 76056146 46863105 685550623 839901898 449378156 95523...
output:
1022634335 430397305 706802927 792928199 234037317 614326837 19604859 174618205 573247941 328350162 754864326 21056750 405182427 4017809 417413741 123839444 360657272 754875606 257082604 238772157 68404383 24531669 10043144 339387299 1064465494 311607662 712701551 681289734 321677103 742046016 26866...
result:
wrong answer 115th numbers differ - expected: '-1', found: '966968555'
Test #21:
score: 0
Wrong Answer
time: 66ms
memory: 5640kb
input:
88850 169104 439219407 133382115 399964746 836979131 645620747 868404708 848737034 58938243 97319244 353759135 1215171 374936400 25992591 115486795 961065913 506783391 82698163 710319392 148676132 729664463 31992473 108553384 67398092 537908730 13852313 155118574 329404335 181982056 930216045 496154...
output:
23086497 24452222 70696960 954321424 70908517 62297318 164171537 286229315 756207570 690781632 576726629 58067731 281107857 286015148 302120160 425977867 657654000 984716290 397495630 406098237 264785863 218843949 789109377 15868388 702174204 251983494 484814430 39280804 994343400 136847969 73734503...
result:
wrong answer 1st numbers differ - expected: '-1', found: '23086497'
Test #22:
score: 0
Runtime Error
input:
100686 276212 871549739 136160440 466533606 358530650 457719179 893818276 827731972 592096685 817772116 185943697 800658414 276247893 739963945 449453970 255084909 125882444 880433752 87861892 128476988 454878151 332781894 612647844 180211299 525852359 108314585 679923461 553988700 275471409 2692542...
output:
result:
Test #23:
score: 0
Wrong Answer
time: 6ms
memory: 5296kb
input:
71770 20174 184364221 351057781 887955123 330631468 743027612 227126917 476703531 191520813 940392109 510754770 82417281 11315438 842595967 295643926 714646834 423509406 136622757 409363353 192817091 758531572 498988374 821290269 480058802 228630481 544012211 715998787 150413218 866446360 8770725 72...
output:
2459332 8236701 234519208 41083936 559056987 632773937 859811649 220302557 955798947 831748309 875962254 276180854 627919684 512086462 87838761 945298259 748952293 894985901 188865443 393317939 715988792 280477582 438443157 821776747 429041352 127748415 318079304 199145839 464534292 692303203 730595...
result:
wrong answer 1st numbers differ - expected: '-1', found: '2459332'
Test #24:
score: 0
Wrong Answer
time: 145ms
memory: 5616kb
input:
87909 232192 840448446 798539162 348086368 316860154 288955927 519879240 53570589 162604471 532434703 847470642 63451649 527196736 821407946 337148398 921744942 398043127 711633512 463878886 799188433 845037842 959124918 445137886 186368588 462692408 497573685 41448214 677400774 935148558 949068213 ...
output:
177985468 299963020 614871681 333627611 290842794 695647533 227539807 530281861 411115913 740743928 53744264 79790024 275899278 241885044 948270950 884193110 780923107 275728023 450621663 298782025 518241030 806053905 512505876 13907444 140463921 184479639 487993594 627045667 492093796 612175597 287...
result:
wrong answer 1st numbers differ - expected: '-1', found: '177985468'
Test #25:
score: 0
Wrong Answer
time: 149ms
memory: 4692kb
input:
44255 241838 306372607 145838026 12744333 277579217 799007713 884285235 294354874 427411240 336661027 222390100 487638233 995501988 830486319 382941773 466029436 721504416 171216448 912534314 360374297 574640391 19876216 922985185 155197303 784807491 21513409 573064275 98966826 789945189 32147274 18...
output:
675706229 912613622 235561175 471020288 52178071 151027693 141266644 409878032 99265915 802876035 333307100 25509884 372035672 992768460 228609685 209289496 681159646 530072540 258136947 349476427 414155644 827924085 277505786 141571473 353171855 236871217 215720133 289317606 17417070 836752466 1072...
result:
wrong answer 1st numbers differ - expected: '-1', found: '675706229'
Test #26:
score: 0
Time Limit Exceeded
input:
146469 105266 687560601 637165872 441062755 584116731 556695856 515380725 585339808 903253758 805470547 357493584 229359761 134463633 156065639 228688299 743405146 382576767 109098874 880362763 738419828 250624618 44896046 118841397 136431313 685391452 67276138 21915261 172678386 326150466 403210766...
output:
result:
Test #27:
score: 0
Runtime Error
input:
112953 202967 197284148 928802535 251937479 121244058 288345774 975569553 787386847 924361223 298271426 323903146 673044180 333269914 65502445 131967789 189709201 790481915 822824468 89085604 274904826 541555685 623488377 273602551 388677449 492681157 876734975 55064512 716538926 994623213 564098007...
output:
result:
Test #28:
score: 0
Wrong Answer
time: 36ms
memory: 4524kb
input:
31437 78846 86857094 881151353 593146160 278108630 406500293 686412410 205681479 179868394 172610736 499973030 543936064 747238933 483715739 180460896 268030784 455270700 694413874 463547835 347514079 692026356 346703794 786009263 534100007 934944507 599505567 340940560 261977671 369493300 211771924...
output:
686417225 140552337 42397712 960211716 776532749 626534113 74449735 749348950 208370398 188377582 977473887 677285940 869925966 753973800 829200509 35804343 31969970 892958516 867999345 474583769 42441681 780166111 302436228 801688098 402354291 769908673 391931861 318452315 147621019 77037423 229897...
result:
wrong answer 1st numbers differ - expected: '-1', found: '686417225'
Test #29:
score: 0
Runtime Error
input:
146155 19544 53461408 808048986 500213095 878164415 999654460 709393475 228471199 919424252 66896735 788719948 555663678 750644591 481969923 694955785 754663033 991994778 742698390 980213089 151399712 193051784 439140743 388837715 954068772 366730069 465171183 766271313 238952337 735839583 264773286...
output:
result:
Test #30:
score: 0
Time Limit Exceeded
input:
112696 57845 47907900 343450520 89144409 440456264 667543391 303895553 210902706 781845523 713539202 146722972 969702927 847501427 938093585 911332046 426960599 881156825 49738742 286641108 661570895 153564993 724415099 844706297 133510385 692926046 82731928 239636558 544427419 969092958 564525153 8...