QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401291 | #6409. Classical Data Structure Problem | Siilhouette | TL | 1217ms | 36756kb | C++23 | 3.2kb | 2024-04-28 13:28:56 | 2024-04-28 13:28:57 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC target("fma","avx2")
#pragma GCC target("xop","fma4")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#define _CRT_SECURE_NO_WARNINGS
#include<set>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2100010;
const int mod=1ll<<30;
int n,m,tot,root,a[N];
struct Node{
int siz;unsigned sum; //区间长度 区间每一个元素被加了多少
Node(){}
Node(int _siz,unsigned _sum):siz(_siz),sum(_sum){}
};
struct fhq{
int l,r,dat,siz;Node val;unsigned sum,add;
#define l(x) t[x].l
#define r(x) t[x].r
#define add(x) t[x].add
#define sum(x) t[x].sum
#define val(x) t[x].val
#define siz(x) t[x].siz
#define dat(x) t[x].dat
}t[N];
inline int nou(Node x)
{
val(++tot)=x;dat(tot)=rand();siz(tot)=x.siz;sum(tot)=x.siz*x.sum;
add(tot)=0;
return tot;
}
inline void update(int p)
{
siz(p)=siz(l(p))+val(p).siz+siz(r(p));
sum(p)=val(p).sum*val(p).siz;
if(l(p))sum(p)+=sum(l(p));
if(r(p))sum(p)+=sum(r(p));
}
inline void spread(int p)
{
if(!add(p))return;
if(l(p))sum(l(p))+=siz(l(p))*add(p),
add(l(p))+=add(p),
val(l(p)).sum+=add(p);
if(r(p))sum(r(p))+=siz(r(p))*add(p),
add(r(p))+=add(p),
val(r(p)).sum+=add(p);
add(p)=0;
}
inline void split(int p,int &x,int &y,int v)
{
if(!p)return x=y=0,void();
spread(p);
if(siz(l(p))+1ll*val(p).siz<=v)
x=p,split(r(p),r(p),y,v-siz(l(p))-val(p).siz);
else if(siz(l(p))>=v)
y=p,split(l(p),x,l(p),v);
else
{
v-=siz(l(p));
Node tem=val(p);
x=p,y=++tot;val(p).siz=v;
val(y).siz=1ll*tem.siz-v;
val(y).sum=val(p).sum;
siz(x)=val(x).siz;
siz(y)=val(y).siz;
//dat(y)=dat(x);
dat(y)=rand();
sum(x)=val(x).siz*val(x).sum;
sum(y)=val(y).siz*val(y).sum;
add(x)=add(y)=0;
l(y)=0;r(y)=r(x);
r(x)=0;
update(x),update(y);
return;
}
update(p);
}
inline int merge(int x,int y)
{
if(!x||!y)return x^y;
if(dat(x)<dat(y))
return spread(x),r(x)=merge(r(x),y),update(x),x;
else return spread(y),l(y)=merge(x,l(y)),update(y),y;
}
inline unsigned change(int p,int q,unsigned v)
{
int x,y,z;unsigned res=0;
split(root,x,y,p-1);
split(y,y,z,q-p+1);
add(y)+=v;
sum(y)+=siz(y)*v;
val(y).sum+=v;
res=sum(y);
root=merge(merge(x,y),z);
return res;
}
inline int g()
{
register int res=0;
char ch;
while(!isdigit(ch=getchar()));
do res=res*10+(ch^'0');
while(isdigit(ch=getchar()));
return res;
}
inline void out(int x)
{
if(x>9)out(x/10);
putchar(x%10+'0');
}
signed main()
{
srand(time(0)+32213);
srand(rand());
n=g(),m=g();
root=merge(root,nou(Node(1ll<<m,0)));
unsigned ans=0,m2=1ll<<m;
int p,q;
for(int _=1;_<=n;_++)
{
p=g(),q=g();
p=(1ll*p+ans)%m2+1,q=(1ll*q+ans)%m2+1;
if(p>q)swap(p,q);
ans=(ans+change(p,q,1u*_))%mod;
//printf("%lld\n",ans);
}
out(1*ans%mod);
putchar('\n');
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3708kb
input:
5 2 2 1 1 3 3 2 1 0 0 2
output:
87
result:
ok 1 number(s): "87"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
1 2 3 1
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
1 5 31 15
output:
17
result:
ok 1 number(s): "17"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
1 20 366738 218765
output:
147974
result:
ok 1 number(s): "147974"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
1 30 86669484 41969116
output:
44700369
result:
ok 1 number(s): "44700369"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
10 5 20 31 2 2 14 18 13 25 26 4 22 9 15 9 19 16 15 27 9 20
output:
1414
result:
ok 1 number(s): "1414"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
100 10 245 987 817 813 743 560 548 504 116 479 223 199 775 998 126 542 791 823 96 318 69 349 0 584 245 601 119 513 93 820 115 307 838 978 249 767 433 287 240 8 22 683 169 720 395 592 903 866 919 652 510 563 858 345 938 250 550 239 981 7 784 926 212 644 272 365 490 871 470 987 571 53 65 593 515 370 1...
output:
20383734
result:
ok 1 number(s): "20383734"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
1000 1 0 1 1 0 1 0 1 0 1 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0 1 1 1 0 1 0 1 0 0 1 1 1 0 0 1 1 1 0 0 0 1 0 0 1 1 1 0 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 1 0 1 0 0 1 1 1 1 0 1 0 0 0 1 0 1 1 1 1 0 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 0 0 1 0 0 0 1 0 0 0 0 1 1 0 1 1 1 0 0 0 1 0 1 1 0 0 1 0 0 0 0 0 0 1 1 1 1 1...
output:
190098735
result:
ok 1 number(s): "190098735"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
1000 5 8 18 31 28 19 3 15 28 5 22 19 1 26 27 17 17 5 26 6 27 10 6 5 2 3 19 6 6 28 16 17 16 0 21 7 31 13 25 13 10 28 30 0 13 21 5 2 9 25 28 4 18 31 13 1 26 30 3 5 8 19 16 22 10 15 17 3 25 6 27 18 26 27 1 26 29 18 21 14 20 5 1 26 9 7 13 19 25 15 11 24 17 12 28 24 17 4 27 20 27 31 18 25 17 1 28 5 0 16 ...
output:
794181769
result:
ok 1 number(s): "794181769"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3736kb
input:
1000 10 732 399 190 578 491 867 330 55 113 400 34 734 790 927 201 156 107 359 790 398 401 523 634 505 570 305 281 513 551 35 610 33 231 330 833 756 213 444 412 315 139 165 533 21 35 977 319 884 894 72 149 667 16 538 282 860 850 550 100 99 801 138 159 34 468 852 840 853 368 994 469 906 393 298 464 89...
output:
755182648
result:
ok 1 number(s): "755182648"
Test #12:
score: 0
Accepted
time: 5ms
memory: 3852kb
input:
5000 15 7705 10737 21186 31441 10307 825 19372 1969 32358 6343 22487 31897 12802 25210 17920 4297 5726 8409 28174 12489 16532 12646 9916 14917 19592 26927 23987 9279 26951 31081 3673 10505 20727 10730 28961 26581 11005 29624 13931 32180 29764 19108 23553 28977 30178 6537 25586 3041 15333 31927 4671 ...
output:
374742544
result:
ok 1 number(s): "374742544"
Test #13:
score: 0
Accepted
time: 7ms
memory: 5688kb
input:
10000 20 914013 637387 162942 785196 55799 893293 359726 714014 109456 559963 689320 161360 164737 25370 260018 436870 801394 34900 564741 620583 1008448 956143 788249 695007 633673 1020122 431990 397822 253241 746513 322933 927863 843120 378180 343689 583409 788822 249760 839003 753443 910418 20908...
output:
719391110
result:
ok 1 number(s): "719391110"
Test #14:
score: 0
Accepted
time: 154ms
memory: 10484kb
input:
100000 30 1063412225 224331901 116583527 514118426 121269548 678461017 856756753 250958443 1064104926 412721149 829078609 544244155 734000135 742933979 9127283 962205064 595091107 123655320 593251579 687018764 1052215261 661849950 297391487 243419322 105274358 526149321 1069300711 46673358 208918023...
output:
252791218
result:
ok 1 number(s): "252791218"
Test #15:
score: 0
Accepted
time: 363ms
memory: 16524kb
input:
200000 30 340892656 331749003 569148929 1001014926 169562315 65082998 783728999 371358574 1068579249 78668714 697845492 972638257 499257742 966955403 924540097 249425391 76210210 270676008 1055790206 117898225 186726707 639941146 774774929 469533012 608214477 15295274 30556605 466457599 892407954 78...
output:
220823398
result:
ok 1 number(s): "220823398"
Test #16:
score: 0
Accepted
time: 631ms
memory: 22604kb
input:
300000 30 692114910 439166105 1021714331 414169601 217855081 525446803 710701245 491758705 1073053571 818358104 566612376 327290534 264515348 117235003 766211086 610387541 631071137 417696697 444587009 622519510 394979978 618032341 178416548 695646703 37412772 578183052 65554323 886241839 502156061 ...
output:
501248752
result:
ok 1 number(s): "501248752"
Test #17:
score: 0
Accepted
time: 983ms
memory: 30224kb
input:
400000 30 1043337164 546583208 400537910 901066101 266147848 985810608 637673490 612158836 3786069 484305669 435379259 755684636 29772955 341256427 607882075 971349692 112190239 564717385 907125636 53398971 603233248 596123536 655799990 921760394 540352891 67329005 100552041 232284256 111904168 9990...
output:
828770668
result:
ok 1 number(s): "828770668"
Test #18:
score: 0
Accepted
time: 1217ms
memory: 36756kb
input:
500000 30 320817594 654000310 853103312 314220777 314440615 372432589 564645736 732558967 8260392 150253235 304146143 110336914 868772386 565277851 449553064 258570018 667051166 711738073 295922440 558020255 811486519 574214731 59441609 74132260 1043293010 630216783 135549759 652068497 795394100 298...
output:
906730214
result:
ok 1 number(s): "906730214"
Test #19:
score: 0
Accepted
time: 21ms
memory: 3844kb
input:
500000 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 0 1 1 0 0 0 0 1 0 1 1 0 0 0 1 0 1 1 0 0 1 1 0 1 1 1 1 1 0 0 1 0 0 0 0 1 1 1 1 0 0 1 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 0 0 1 1 0 1 1 1 1 1 0 0 1 0 0 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 1 1 0 1 1 0 1 1 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1...
output:
181097888
result:
ok 1 number(s): "181097888"
Test #20:
score: 0
Accepted
time: 34ms
memory: 3784kb
input:
500000 2 1 2 0 1 0 2 3 3 2 1 2 3 0 2 3 2 2 3 1 3 0 2 1 1 1 1 3 1 3 1 2 3 1 2 3 0 3 3 0 2 3 3 0 3 0 0 1 3 1 2 1 3 2 0 2 1 1 2 1 3 3 0 2 1 1 2 3 3 1 3 0 2 3 2 0 0 3 0 1 1 2 2 0 2 2 1 2 1 1 2 2 3 1 3 2 2 1 3 1 0 0 0 0 1 1 1 3 3 0 1 1 3 0 3 1 2 2 1 2 1 2 1 1 3 2 3 1 0 2 3 3 0 0 1 0 1 3 1 2 1 3 0 2 1 0 0...
output:
687623855
result:
ok 1 number(s): "687623855"
Test #21:
score: 0
Accepted
time: 103ms
memory: 3640kb
input:
500000 5 14 22 17 2 15 11 17 5 17 15 22 3 11 31 2 28 12 3 15 31 22 24 20 3 30 10 14 25 4 24 4 27 23 10 8 23 27 30 2 0 23 19 7 17 9 12 0 17 18 15 16 8 25 4 21 17 1 15 28 16 0 17 6 10 12 25 27 14 4 10 13 4 2 7 11 0 26 14 5 31 5 3 3 23 25 9 30 13 8 27 4 17 31 3 22 17 20 28 0 10 19 3 6 28 8 27 18 15 25 ...
output:
622835418
result:
ok 1 number(s): "622835418"
Test #22:
score: 0
Accepted
time: 256ms
memory: 3764kb
input:
500000 10 856 970 406 443 765 933 624 432 886 497 85 266 923 446 574 385 406 670 919 782 980 995 653 372 306 566 872 763 820 655 940 777 912 341 566 196 377 90 112 151 791 392 683 663 265 918 544 653 478 477 865 495 731 163 1005 983 207 265 351 501 836 663 145 960 703 609 492 802 854 827 788 98 590 ...
output:
188485208
result:
ok 1 number(s): "188485208"
Test #23:
score: 0
Accepted
time: 557ms
memory: 4784kb
input:
500000 15 27436 19759 17989 14016 29351 9027 22878 23375 493 27515 23549 24903 315 23061 25757 17058 1864 7051 30102 6834 11360 31682 17857 13340 18416 7677 14292 14102 31283 32432 29118 21540 3743 12654 29341 26640 17415 1416 9602 20812 8260 18798 2549 31524 31630 17713 19078 12150 27310 177 10790 ...
output:
1032744914
result:
ok 1 number(s): "1032744914"
Test #24:
score: 0
Accepted
time: 1087ms
memory: 25596kb
input:
500000 20 595399 816452 624541 904856 21003 135407 71017 55007 982408 852317 192118 714368 372925 504868 1038018 323825 533838 690687 615209 673098 374113 789997 887853 227012 666338 73589 1037373 185087 283957 874396 942111 213879 106795 840613 81434 235343 796353 760221 217814 465288 11787 68789 5...
output:
409536009
result:
ok 1 number(s): "409536009"
Test #25:
score: 0
Accepted
time: 1202ms
memory: 34936kb
input:
500000 25 19067802 14544791 25094922 28771765 5655376 16549409 5245489 11514410 2880479 5597148 27471827 6089281 15538101 25124497 7207909 15185410 5672258 7360080 20385827 2897907 25020895 25107624 25287245 8713330 30138363 25200774 19229689 28894790 14249446 6164467 29132724 3420898 10899764 28675...
output:
780249768
result:
ok 1 number(s): "780249768"
Test #26:
score: 0
Accepted
time: 1183ms
memory: 35208kb
input:
500000 28 152614559 168140428 64224198 121918464 122849778 83659627 217295184 192622378 261781773 101788852 214755856 129277082 195293407 29297446 93882848 198320685 259042706 149180743 166442363 41079386 101742327 253721117 26241171 237722709 122360149 203892353 33112297 72988388 192464090 15934624...
output:
436932928
result:
ok 1 number(s): "436932928"
Test #27:
score: 0
Accepted
time: 1174ms
memory: 35180kb
input:
500000 29 305277211 191845285 37424942 350623463 476394371 313785791 14606972 94335544 324808232 241585480 68251928 312262716 79998604 302043143 211912079 89952361 481571536 358561552 335121887 452003467 137868096 184768373 471982058 50585219 165555792 51394869 343655057 219487120 79326582 34132224 ...
output:
416804842
result:
ok 1 number(s): "416804842"
Test #28:
score: -100
Time Limit Exceeded
input:
500000 30 7 536872004 889 536871096 536871568 1073741186 536868404 1073739135 4658 536877000 536884849 16144 536888745 15098 536888517 17983 536978817 109982 537163990 288696 537547118 678741 537975122 1104461 538406486 1536913 2109524 538980240 539586338 2712484 540166099 3292622 3885543 540760294 ...