QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#861587 | #7486. 等这场战争结束之后 | RDFZchenyy | AC ✓ | 272ms | 18564kb | C++17 | 2.0kb | 2025-01-18 18:20:38 | 2025-01-18 18:20:39 |
Judging History
answer
#include<bits/stdc++.h>
#define MAXN 100005
const int bsz=2238;
struct Query{
int op,x,y;
};
int n,m;
int a[MAXN],kth[MAXN];
Query q[MAXN];
std::vector<int> t[MAXN];
int sz[MAXN],f[MAXN],fa[MAXN];
int ans[MAXN];
int bl,br;
bool cmp(int x,int y){
return a[x]<a[y];
}
int find(int x){
if(x==fa[x]) return x;
return find(fa[x]);
}
void dfs(int u){
int fx,fy; fx=fy=0;
if(q[u].op==1){
fx=find(q[u].x),fy=find(q[u].y);
if(fx!=fy){
if(sz[fx]>sz[fy]) std::swap(fx,fy);
fa[fx]=fy; sz[fy]+=sz[fx]; f[fy]+=f[fx];
}else fx=fy=0;
}else if(q[u].op==3){
fx=find(q[u].x);
if(0<q[u].y&&q[u].y<=f[fx]){
for(int i=bl;i<=br;i++){
if(find(kth[i])==fx) q[u].y--;
if(q[u].y==0){
ans[u]=i;
break;
}
}
}else{
if(q[u].y>0) q[u].y-=f[fx];
}
}
for(int v:t[u]){
dfs(v);
}
if(q[u].op==1&&(fx+fy)){
fa[fx]=fx; sz[fy]-=sz[fx]; f[fy]-=f[fx];
}
return;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0); std::cout.tie(0);
std::cin>>n>>m;
for(int i=1;i<=n;i++) std::cin>>a[i],kth[i]=i;
std::sort(kth+1,kth+n+1,cmp);
bl=1;
for(int i=1;i<=n;i++){
fa[i]=i; sz[i]=1;
}
for(int i=1;i<=m;i++){
std::cin>>q[i].op;
if(q[i].op!=2){
std::cin>>q[i].x>>q[i].y;
t[i-1].push_back(i);
}else{
std::cin>>q[i].x;
t[q[i].x].push_back(i);
}
}
for(;bl<=n;bl=br+1){
br=bl+bsz-1; br=std::min(br,n);
for(int i=bl;i<=br;i++) f[kth[i]]=1;
dfs(0);
for(int i=bl;i<=br;i++) f[kth[i]]=0;
}
for(int i=1;i<=m;i++){
if(q[i].op==3){
if(q[i].y) std::cout<<-1<<'\n';
else std::cout<<a[kth[ans[i]]]<<'\n';
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 174ms
memory: 12156kb
input:
100000 100000 151086 92077 151816 225769 163751 153055 106037 255085 226793 8965 245935 255391 52671 104771 150148 45596 176056 19687 28347 242875 278231 82168 82542 186244 155425 15100 209827 25989 152285 97236 50441 45365 33182 263482 128880 75995 211531 201408 14422 202731 259391 93969 178586 202...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 231342 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 253163 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
ok 22249 lines
Test #2:
score: 0
Accepted
time: 78ms
memory: 15688kb
input:
50000 100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...
output:
38625 19727 39679 28804 31677 4757 49305 30626 8432 17305 32389 21001 30069 29192 2441 1749 15676 36107 17465 10291 49663 39291 27235 23393 27486 17045 37969 4175 10267 25069 1697 10601 40721 37313 46431 38098 46609 47665 34068 36717 34126 48783 15441 21686 47297 33851 14353 35700 3665 5996 34583 47...
result:
ok 16667 lines
Test #3:
score: 0
Accepted
time: 100ms
memory: 14316kb
input:
50000 100000 56018626 511753729 306811583 140674987 493190577 222411495 220668110 516191477 146292625 305044571 154624303 373624285 300945851 477514306 471903715 216446677 3827649 20984269 136050808 34948417 224100922 21079722 110371642 545723281 340348690 294587623 102145105 13994581 301197887 4741...
output:
575259980 609387713 307810925 971896321 342210929 183894858 159477154 715885199 301304686 425821969 7499647 480103240 452900296 413282746 643894273 16084615 148654808 179242464 274975857 519511625 190517462 496728244 419999451 170443425 252722783 209423962 109482721 96502463 301426126 548139386 2260...
result:
ok 16531 lines
Test #4:
score: 0
Accepted
time: 94ms
memory: 14384kb
input:
50000 100000 157665187 265393459 44641621 508312801 73266796 269408697 808247459 444579721 517380936 98673403 91156201 169618931 700979497 71777577 168592672 138597553 468975788 18926581 179114226 495976417 257767939 85949719 80869929 149569537 74670389 26016179 698807023 185603932 251559937 2572091...
output:
247870597 92878326 722750374 286468022 254471393 668116065 330217980 23638889 506805489 28050039 70841532 180219293 399536821 230559841 115919189 107967841 360949657 31754401 116456416 39246801 83974983 35327469 728942713 461287393 188266631 189732460 432062113 348164580 149785201 303424511 23480001...
result:
ok 16634 lines
Test #5:
score: 0
Accepted
time: 88ms
memory: 13692kb
input:
100000 100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...
output:
-1 74374 -1 24831 88144 -1 -1 90619 52500 5180 -1 21432 -1 3463 -1 75557 -1 21163 -1 669 -1 96651 74609 55623 30003 -1 70558 80939 -1 62324 -1 -1 -1 96681 -1 29675 -1 -1 -1 -1 32708 48758 60976 -1 -1 -1 -1 -1 -1 -1 -1 53956 35446 -1 16808 -1 25263 30080 19097 87773 74515 -1 61755 -1 68224 6446 2592 ...
result:
ok 4501 lines
Test #6:
score: 0
Accepted
time: 103ms
memory: 13772kb
input:
100000 100000 590166677 184725633 594803041 172560501 74592001 688019817 263217291 229684621 1038774376 83650561 862987497 444029537 353559052 751854220 181091425 87912401 110004226 204984645 110402359 62977249 7218973 200723625 803792146 6539938 935546287 376651840 1035777167 339839809 307429291 62...
output:
14404181 33505633 22353430 10199890 3901411 348435 9492741 4047118 22412461 75630493 38839937 7124906 1406865 4471393 450289 49015801 49396486 17109821 110401189 17560685 46653517 16458423 27286820 1315711 -1 185511069 538288609 20606818 12056786 13212789 656964601 181587901 37066009 12596041 121555...
result:
ok 4501 lines
Test #7:
score: 0
Accepted
time: 106ms
memory: 13500kb
input:
100000 100000 179870069 336846580 707372478 718482493 91929586 66080476 202531 106613035 273697672 323387581 379762048 336822751 27494292 200188276 254009057 885693901 25633126 103493501 39528631 180908401 417126021 620503269 127193743 83137201 466566723 38779795 912474359 46213561 613542217 5701023...
output:
118962901 -1 -1 4445813 30689745 257008161 -1 -1 175862449 680577345 -1 -1 194969506 -1 -1 181654745 -1 -1 1021261377 -1 58480470 90395890 58051918 -1 17198380 -1 26379189 -1 2674441 176390411 180688327 27024621 -1 83872510 105968895 -1 -1 13961269 -1 29929057 264687937 210083191 -1 218648433 162836...
result:
ok 4501 lines
Test #8:
score: 0
Accepted
time: 119ms
memory: 18508kb
input:
100000 100000 579490073 3709423 230768641 19974455 181266923 5237083 552795043 71579259 36364601 9209601 269268407 7916336 117298609 882858955 78778657 298669525 33339705 48848115 216044185 282502536 326797985 16326531 16801953 78002810 247788736 283850683 372029293 66633031 27955708 197466721 94064...
output:
41388603
result:
ok single line: '41388603'
Test #9:
score: 0
Accepted
time: 98ms
memory: 13000kb
input:
100000 100000 37555211 392685906 851486140 18768376 26125831 328713301 92378103 218222071 99058 10305107 130042879 409675696 105301271 435328449 497359894 563904325 89334001 104808263 823167736 28514498 157882894 21462721 19099297 222835701 41963232 37127599 49139317 610411735 53461237 327951137 640...
output:
37801193 86978917 107374786 20131657 94821275 11275777 126750821 132385510 5526067 109566076 45513631 226801351 41869339 53417995 18385102 -1 55088741 1397047 87988771 5819254 14028418 39103765 549980107 3637359 63952201 81276712 8625529 67411918 81852716 53506753 298366667 118407836 63766546 341509...
result:
ok 8182 lines
Test #10:
score: 0
Accepted
time: 123ms
memory: 12592kb
input:
100000 100000 1955067 3997147 2887730 1652504 3165965 757618 3490967 363076 2939036 4401042 2265008 1540341 4346356 1478772 3336695 1475068 1685426 225781 2551795 1740096 2052661 2818910 1837036 2137795 1823843 2015221 4444912 1699161 2571700 1221838 850154 4080047 290161 1861951 1048726 1058553 149...
output:
-1 4301168 -1 -1 3438543 -1 -1 -1 1172321 -1 -1 2893011 2105153 2048616 -1 4288532 -1 -1 1841586 -1 -1 -1 1108901 3557079 3869399 -1 510320 -1 3171936 -1 -1 -1 2835746 -1 -1 -1 871893 -1 -1 2001202 -1 2747914 1817643 -1 3110731 -1 -1 119761 -1 -1 -1 1562446 3788001 825852 2605463 -1 1875091 -1 -1 40...
result:
ok 5996 lines
Test #11:
score: 0
Accepted
time: 272ms
memory: 18564kb
input:
100000 100000 481610881 240419940 153849133 793211966 608768689 57882817 459914761 170238421 9928101 132847321 95916745 99493317 11198960 524286036 303003501 97691361 635801953 26210401 105429424 193992449 584863929 255974221 3936835 115914021 298935418 2599523 268687387 73309700 654455629 755148097...
output:
-1 -1 36060373 -1 -1 -1 52078177 -1 -1 -1 501006223 -1 -1 -1 160411457 641992321 -1 443301985 46088901 -1 112137371 812478412 115514677 505193855 851130116 117395081 69329398 801515457 356974651 220869699 369479254 649758287 61569691 467873545 9169513 178250011 6008254 835729597 383738441 380992886 ...
result:
ok 16022 lines
Test #12:
score: 0
Accepted
time: 215ms
memory: 16068kb
input:
100000 100000 525929746 10159885 182748684 175132907 52221133 636645125 1627777 437824786 274942389 462386437 501652001 616404999 636442311 451998163 236723992 38437417 176770661 281736925 163582171 418538781 52362459 686638871 2521063 304347802 182011961 293755619 106879501 408154509 335516251 6851...
output:
7009 230117669 -1 -1 172541524 -1 2187067 620221681 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 764106139 2173268 86774065 117366081 553958035 709922603 498574356 126851076 6745137 -1 188671815 -1 75836521 -1 306684331 10843721 139467083 132528397 -1 81740935 -1 830891649 -1 15182901 147742217 -1 -1 3204467 -1 56...
result:
ok 15803 lines
Test #13:
score: 0
Accepted
time: 189ms
memory: 16076kb
input:
100000 100000 60899679 1754696 2330875 490675641 96220041 36401995 268255033 30322930 14971441 352813501 268525401 122406274 170453323 4038013 137453993 300949468 342633577 48065401 159121516 456081792 912288049 815800231 6165001 128372513 547139915 25969074 255490313 32990140 1938355 403236563 5849...
output:
87125743 70150130 77272910 27068875 -1 21300301 -1 97561585 -1 83435491 131784706 86558958 -1 518695178 368147165 -1 -1 -1 -1 495033232 87953963 -1 -1 77287081 -1 59037705 97891759 -1 -1 -1 -1 -1 35223501 -1 7437745 899879 53868153 -1 49756761 51871540 3209737 -1 34995628 -1 -1 -1 -1 -1 -1 109516671...
result:
ok 20000 lines
Test #14:
score: 0
Accepted
time: 144ms
memory: 15948kb
input:
100000 100000 495606556 17093041 310995185 306348316 579125878 259727249 92816989 122100461 74926056 59764402 403727815 294270367 37707361 30872155 100060225 425993569 246248918 37694834 294428017 136441817 850224316 280299691 91538913 21449863 343391266 260286406 918221860 393520030 92754880 885543...
output:
64826863 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 40113793 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 105509821 -1 -1 -1 -1 3072304 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 465461324 -1 97800143 -1 -1 -1 -1 -1 -1 -1 -1 -1 127798795 -1 -1 -...
result:
ok 16014 lines
Test #15:
score: 0
Accepted
time: 143ms
memory: 16072kb
input:
100000 100000 8640469 150078721 85576321 207173156 753310647 161272639 11486161 744542085 521440921 350065425 187990301 619811433 320402881 10662625 863121913 457454647 144311169 240525019 129338434 387617121 469021762 19366093 26330305 557635091 253307027 342514063 36385495 101684491 302326444 2081...
output:
38370949 -1 -1 -1 469021762 -1 97098433 -1 619221493 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 215822811 199240787 -1 -1 459479497 861760869 -1 626221311 789258373 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 279944911 151044999 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 27940541 -1 -1 -1 -1 -1 -1 -1...
result:
ok 16811 lines
Test #16:
score: 0
Accepted
time: 166ms
memory: 15940kb
input:
100000 100000 87216001 271308031 298117356 69061189 219907505 22140801 468716249 633561589 54059580 233482551 324482236 545750657 122319961 259471210 232804515 36237559 14244957 247249900 291691456 816433129 536083887 356778753 19544595 288445971 12268397 663342776 274549618 113516265 263349461 3600...
output:
72192583 -1 511267021 459647204 234180100 55429521 -1 509766841 397779499 281946178 310600396 -1 732835566 1259239 -1 229240561 152772211 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 159706251 328466650 577926401 301877255 303898529 59902051 -1 275843941 307264021 -1 54614331 -1 165477961 452347930 -1 -1 -1 ...
result:
ok 16816 lines
Test #17:
score: 0
Accepted
time: 155ms
memory: 15944kb
input:
100000 100000 393091553 52629131 157285361 445324225 62328070 42128025 431016785 87385731 511443228 921427779 237049763 83180256 62477087 52186331 53672029 2371255 171916885 581346510 313232941 616392955 139835541 555672217 383115364 316949110 154786681 39422383 216741021 41941831 61846936 165959407...
output:
-1 -1 271908841 -1 -1 -1 -1 -1 -1 -1 30613651 302875106 -1 20208737 -1 -1 -1 -1 -1 -1 -1 -1 -1 391312963 -1 -1 -1 -1 -1 -1 -1 -1 33631545 68709369 -1 130744054 -1 247738001 48511990 -1 -1 -1 532692057 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 647680926 131511871 -1 -1 -1 -1 140743929 ...
result:
ok 16745 lines
Test #18:
score: 0
Accepted
time: 117ms
memory: 14540kb
input:
100000 100000 614578969 825714681 513100204 26254125 24890293 148485331 123700887 383084906 68669953 206898589 72849456 122107441 69561025 726750142 236224871 140886529 571076360 71074323 4716281 319964971 33037801 100670005 353512727 33187690 357316325 187133805 71299242 673327873 24539161 12594941...
output:
50127621 964595877 642418126 398294046 889674661 90808321 53044699 136858177 173024353 414989454 63156781 353373659 11484757 122212801 241114231 412203721 505441 2706 234778663 501519313 15156835 20080266 179430016 380183395 69686079 63040021 222738151 155603233 42073291 29378381 203262269 214669065...
result:
ok 20001 lines
Test #19:
score: 0
Accepted
time: 113ms
memory: 15820kb
input:
100000 100000 392299585 581223716 566700014 366995521 163716553 863885176 105892752 86386798 81549161 70815031 326831701 363197521 187230177 96796849 661425948 217522185 2220456 256967701 235709245 127887873 75003185 1304234 52731211 182461384 60058710 47989471 349963576 55150595 747728987 255498832...
output:
47984157 146405645 137283476 189098937 150608305 138515875 42703981 138711883 527594641 124893847 487307251 64128113 249969633 41545936 392175081 290211244 162733762 670264087 251083779 201190271 12983939 57668666 95392416 145554817 53963497 280017820 93392641 120808086 750539091 234242455 34155301 ...
result:
ok 13334 lines
Test #20:
score: 0
Accepted
time: 117ms
memory: 12616kb
input:
100000 100000 889772 813833 1657340 2321529 992272 2068135 1041091 989849 97022 1406191 348761 533371 1652764 2707213 1673290 115040 2433799 2702233 1368787 2719556 1898603 49712 1405714 1518841 1542265 934744 1349982 2196002 2562694 921788 2202079 1652991 1616227 2070052 2331167 367234 1087002 1627...
output:
-1 -1 561757 409980 -1 -1 -1 -1 -1 1309009 -1 -1 -1 -1 -1 -1 -1 -1 2189605 2656393 1873642 -1 -1 -1 -1 2330827 1747508 -1 -1 -1 -1 596051 1328160 -1 -1 1490313 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 565902 374761 -1 -1 803601 -1 1226150 -1 1109743 -1 -1 -1 2400025 -1 -1 597970 -1 -1 -1 2330965 -1 -1...
result:
ok 1932 lines
Test #21:
score: 0
Accepted
time: 117ms
memory: 14624kb
input:
100000 100000 182505793 32892658 377349775 191483545 777895007 169820680 319358425 363908786 355880644 20835361 216780336 466474271 68111225 971419366 74694115 65848652 720189031 8737275 103534421 456321669 98181226 585585396 5436861 505932550 837580381 629380877 746327713 263126404 231420769 167785...
output:
32892658 481492474 469469737 730093425 216905365 109647217 2840471 29700481 438750261 419306181 141889021 329274134 134055328 413699591 401307832 472960117 1 674513988 707131051 431972235 115398241 171300081 107285876 91472570 418209457 409193165 141354277 552153802 473282793 159913561 135998157 914...
result:
ok 20271 lines
Test #22:
score: 0
Accepted
time: 116ms
memory: 13128kb
input:
100000 100000 104801593 64981806 130084937 321842905 34812762 172871305 120622175 434279356 276284773 968044001 478979467 598232403 11931340 379565491 174066621 156477666 42719657 2523465 211984321 628977376 476043076 86191941 590206584 30295501 57248383 94956969 146133846 45861630 581702040 9329709...
output:
64981806 118411833 163731553 155255423 130104199 57248383 3976113 274348417 9906337 89335659 243585849 349974073 249149759 156299617 296357990 1759156 670147234 240866417 602392051 26967577 72579053 424827262 64886977 193682329 9837353 156477666 132833422 45646399 227247866 333275305 264401872 35337...
result:
ok 26802 lines
Test #23:
score: 0
Accepted
time: 107ms
memory: 18376kb
input:
100000 100000 1461409 9133345 133648767 15408713 71869325 307084343 24810176 435472584 138951400 880990462 342212509 205009201 23322905 53792699 34138651 912744149 304510186 11089963 511352971 920122159 302062101 179110615 110049655 212331457 152382832 254838025 794961082 393132104 39130246 51346008...
output:
1461409 12963241 307084343 568253449 642584565 149642541 243623201 138951400 242980193 243623201 108709052 439609321 95086161 448226891 231083403 429902236 123737153 181019608 497522047 524872941 1587745 376979002 3215719 873396379 87162163 145943196 394274316 496847205 134447829 183129751 37840828 ...
result:
ok 3941 lines
Test #24:
score: 0
Accepted
time: 119ms
memory: 12488kb
input:
100000 100000 2513481 3214547 2023549 1842328 855913 548046 3484984 171924 4654581 3359722 1788556 1069121 4759854 4691445 836990 3128462 4236471 884001 325875 3998635 4026327 2859733 26287 373066 1652571 1818279 756465 2366811 3860242 1490821 1192611 1983793 3758061 4165525 2263648 1898295 445573 1...
output:
-1 4399048 -1 4254086 -1 1521627 -1 -1 972181 -1 -1 540376 1017383 -1 -1 213619 -1 132463 5221 4543150 -1 3964246 718777 -1 -1 4010276 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 349054 -1 -1 -1 -1 -1 -1 774361 3653388 4137955 3349315 -1 -1 -1 4350851 -1 1124108 -1 -1 -1 -1 78750 -1 4202053 -1 1120168...
result:
ok 1995 lines
Test #25:
score: 0
Accepted
time: 120ms
memory: 12616kb
input:
100000 100000 228771 32794 268408 401445 477944 418450 6602 325696 354678 370688 304889 247239 35766 405563 307370 384346 70030 178839 41632 196237 181416 337099 148352 422742 336390 141145 16693 296626 295670 27451 308791 399030 359519 403722 468428 395957 17587 353366 192251 74506 206062 302544 11...
output:
-1 -1 -1 -1 -1 -1 -1 225082 426472 179641 347471 246809 -1 -1 -1 417721 300885 -1 -1 384394 280604 -1 291314 -1 286201 -1 -1 111970 254547 -1 -1 -1 -1 168864 302659 -1 -1 296618 -1 -1 -1 -1 -1 71832 -1 -1 -1 -1 -1 96928 -1 49510 -1 -1 -1 -1 -1 -1 367730 445654 -1 -1 -1 281426 353467 -1 -1 355276 396...
result:
ok 2026 lines