QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#213061 | #7452. rupq | Crysfly | AC ✓ | 2372ms | 310316kb | C++17 | 3.8kb | 2023-10-14 10:48:00 | 2023-10-14 10:42:33 |
Judging History
你现在查看的是最新测评结果
- [2023-10-14 10:48:00]
- 提交
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
//#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 2000505
#define inf 0x3f3f3f3f
struct dat{
unsigned mx,t0,t1,cnt;
dat(unsigned MX=0,unsigned T0=0,unsigned T1=0,unsigned C=0){mx=MX,t0=T0,t1=T1,cnt=C;}
dat operator +(const dat&b)const{
dat c;
c.mx=max(mx,b.mx);
c.t0=((~t0&b.t0)|(t0&b.t1));
c.t1=((~t1&b.t0)|(t1&b.t1));
c.cnt=cnt+b.cnt;
return c;
}
void clr(){mx=cnt=t0=0,t1=-1;}
};
int n,m,wa[maxn],wb[maxn];
#define N 5000005
int ls[N],rs[N],sz[N];
dat lv[N],rv[N],res[N];
// res[u] : 合并时,中间一段剩余的答案
int rub[maxn],top,cnt,rt;
inline int newn(){return top?rub[top--]:++cnt;}
inline void thro(int u){rub[++top]=u;}
inline int newn(int w1,signed w2){
int u=newn();
ls[u]=rs[u]=0; sz[u]=1; lv[u].clr(),rv[u].clr(),res[u].clr();
if(w1) rv[u]=dat(w2,-1,~w2,1);
else lv[u]=dat(w2,-1,~w2,1);
return u;
}
dat askr(int u,int k){
if(k==rv[u].cnt) return rv[u];
int l=ls[u],r=rs[u];
if(rv[l].cnt<=lv[r].cnt) return askr(r,k);
int d=rv[l].cnt-lv[r].cnt;
if(d>=k) return askr(l,k);
return res[u]+askr(r,k-d);
}
dat askl(int u,int k){
if(k==lv[u].cnt) return lv[u];
int l=ls[u],r=rs[u];
if(rv[l].cnt>=lv[r].cnt) return askl(l,k);
int d=lv[r].cnt-rv[l].cnt;
if(k<=d) return askl(r,k);
return askl(l,k-d)+res[u];
}
void up(int u){
int l=ls[u],r=rs[u];
sz[u]=sz[l]+sz[r];
if(rv[l].cnt>lv[r].cnt){
res[u]=askr(l,rv[l].cnt-lv[r].cnt);
lv[u]=lv[l];
rv[u]=res[u]+rv[r];
}
else if(rv[l].cnt<lv[r].cnt){
res[u]=askl(r,lv[r].cnt-rv[l].cnt);
lv[u]=lv[l]+res[u];
rv[u]=rv[r];
}
else lv[u]=lv[l],rv[u]=rv[r],res[u]=dat(0,0,-1,0);
}
inline int up(int u,int v){
int w=newn();
return ls[w]=u,rs[w]=v,up(w),w;
}
int build(int l,int r){
if(l==r)return newn(wa[l],wb[l]);
int mid=l+r>>1;
return up(build(l,mid),build(mid+1,r));
}
// this merge is fake!!!
int merge(int u,int v){
if(!u||!v)return u|v;
int t;
if(sz[u]>sz[v]*4) return t=up(ls[u],merge(rs[u],v)),thro(u),t;
if(sz[v]>sz[u]*4) return t=up(merge(u,ls[v]),rs[v]),thro(v),t;
return up(u,v);
}
void split(int p,int k,int&x,int&y){
if(!k)return x=0,y=p,void();
if(sz[p]==1)return x=p,y=0,void();
if(k<=sz[ls[p]]) split(ls[p],k,x,y),thro(p),y=merge(y,rs[p]);
else split(rs[p],k-sz[ls[p]],x,y),thro(p),x=merge(ls[p],x);
}
// query:
int split(int p,int l,int r){
if(l==1 && r==sz[p])return p;
int mid=sz[ls[p]];
if(r<=mid) return split(ls[p],l,r);
if(l>mid) return split(rs[p],l-mid,r-mid);
return up(split(ls[p],l,mid),split(rs[p],1,r-mid));
}
unsigned ask(int l,int r){
int cnt0=cnt,top0=top;
int u=split(rt,l,r);
cnt=cnt0,top=top0;
dat ret=(lv[u]+rv[u]);
return (ret.mx^ret.t1);
}
void mdf1(int p,int x,int w){
if(sz[p]==1){
if(rv[p].cnt) rv[p].clr(),lv[p]=dat(w,-1,~w,1);
else lv[p].clr(),rv[p]=dat(w,-1,~w,1);
return;
}
int mid=sz[ls[p]];
if(x<=mid)mdf1(ls[p],x,w);
else mdf1(rs[p],x-mid,w);
up(p);
}
void mdf2(int l,int r){
int x,y,z;
split(rt,l-1,x,y),split(y,r-l+1,y,z);
rt=merge(merge(x,z),y);
}
signed main()
{
n=read(),m=read();
For(i,1,n)wa[i]=read(),wb[i]=read();
rt=build(1,n);
For(i,1,m){
int op=read(),x=read(),y=read();
if(op==1) mdf1(rt,x,y);
else if(op==2) printf("%u\n",ask(x,y));
else mdf2(x,y);
}
return 0;
}
/*
10 10
0 1
1 9
1 2
0 5
1 1
0 6
1 1
0 4
0 8
1 7
2 5 7
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 603ms
memory: 307268kb
input:
2000000 200000 0 4169 0 2295 0 438 0 8491 0 2049 0 3434 0 5001 0 6732 0 6605 0 7428 0 7604 0 1872 0 658 0 6166 0 755 0 10000 0 8418 0 9862 0 3963 0 7680 0 6985 0 1389 0 8331 0 1522 0 9855 0 6468 0 3296 0 3754 0 9782 0 7213 0 6321 0 1295 0 3529 0 5877 0 9864 0 6590 0 3115 0 4554 0 9093 0 4268 0 7761 ...
output:
4294952935 4294951678 4294956732 4294954895 4294966956 4294951765 4294957545 4294954732 4294965487 4294955066 4294965805 4294957617 4294952169 4294958181 4294957167 4294957225 4294953123 4294953705 4294957162 4294957796 4294957348 4294957422 4294958571 4294957247 4294956743 4294951135 4294955262 429...
result:
ok 66846 numbers
Test #2:
score: 0
Accepted
time: 635ms
memory: 306912kb
input:
2000000 200000 1 806644445 1 619803767 1 629972715 1 474436725 1 564809772 1 882100017 1 807632063 1 635854183 1 853288911 1 213859483 1 227851464 1 292276106 1 578492253 1 560913971 1 386278817 1 980593969 1 870207495 1 809696612 1 113672943 1 100137977 1 437204340 1 892272439 1 900060787 1 6202211...
output:
3691533521 3697891911 3998324052 4088674016 3413968918 3248316444 3999602266 3521155171 3859655242 3814675053 3827833304 3781382252 3757696689 3574977949 4149158915 3826537603 3967571680 3503799947 3983319647 3715443260 3312507150 3460159114 3581219884 3269194329 3292911549 3294592304 3561253774 387...
result:
ok 66466 numbers
Test #3:
score: 0
Accepted
time: 2372ms
memory: 306680kb
input:
2000000 200000 0 259633020 0 306858216 0 196788407 0 588286712 0 348282225 0 584571548 0 60879596 0 709255165 0 167834465 0 488829381 0 554449718 0 750452700 0 750800456 0 776590449 0 551231610 0 581171764 0 486445883 0 970192676 0 156236533 0 737393600 0 448823668 0 621917709 0 308004795 0 78877298...
output:
3696594960 3840417069 3577170014 3580899376 3235910801 3593107211 3697579024 3602993165 3508606320 3428877329 3907585396 4067405438 3233174239 3497671116 3864436272 3293475745 3307244633 3704537115 3590487129 3699217760 3268178383 3244230024 3404023971 3979168621 3706175025 3505290055 3324841746 322...
result:
ok 66836 numbers
Test #4:
score: 0
Accepted
time: 1915ms
memory: 307972kb
input:
2000000 200000 0 195080619 0 301732494 0 515663458 0 392308864 0 883403965 0 648722231 0 276105928 0 713279999 0 270255832 0 237805818 0 139914927 1 596668517 0 145236164 0 754648114 0 61769501 0 33383546 0 627200972 0 290707501 0 171654354 0 189295866 0 904130315 0 173435765 0 111915893 0 376075648...
output:
3732214703 3438107738 3698136510 3890308008 3420971436 3290182424 3962508918 3611732036 3829881898 3370856896 4031734252 3796264403 3288366192 3376236514 3328517455 4100670521 3870151586 3758159840 3456570848 3655701237 3967176067 3589654394 3489383117 3622602350 3571926442 3760486277 3862635905 332...
result:
ok 66899 numbers
Test #5:
score: 0
Accepted
time: 1918ms
memory: 306960kb
input:
2000000 200000 0 980236237 0 862326365 0 484700885 0 449373286 0 823219462 0 282739509 0 236749147 0 805579794 0 351845259 0 433761620 0 838419892 0 711720662 0 363108942 0 447293181 0 888574239 0 207835817 0 953010283 0 701355315 0 695455646 0 681178782 0 397007221 0 884631464 0 534791723 0 3870636...
output:
3351634287 3840235197 3311732343 3501077587 3296019841 3336916397 3430805307 3296708331 3745733957 3825492520 3764864083 3324600235 3543123669 3862506239 3786667903 3329667945 3770733475 3562500968 3792286854 3626456252 3478248623 3991908321 3578039188 3696849707 3462749960 3261154658 3427269875 423...
result:
ok 66591 numbers
Test #6:
score: 0
Accepted
time: 1349ms
memory: 309228kb
input:
2000000 200000 0 957225752 0 784567730 1 349171761 0 861278300 0 922668031 0 945111031 1 609422138 0 550200996 1 60929492 1 481301147 0 886739355 0 884705215 0 172107097 0 603152565 0 354256595 0 600562194 0 784514678 0 492910147 0 116780604 1 296006201 1 205084341 0 836947788 0 482975200 0 27936116...
output:
3622299120 3563787719 4070677393 3267386776 3301297695 3462448076 3538508070 3698774094 3693360379 3563607153 3508881628 3534019985 3738265133 3571535471 3556879556 3836611146 3611670565 3902078973 3570755901 3749471374 3312672424 3325210111 3979589861 3226312254 3830803350 3563503932 3361075473 379...
result:
ok 66994 numbers
Test #7:
score: 0
Accepted
time: 957ms
memory: 308036kb
input:
2000000 200000 0 792026824 0 32745180 0 357788415 0 695168252 0 35928789 0 53746044 0 848719614 0 854362726 0 399252089 0 21745488 0 561948889 0 509958161 0 418166293 0 784425958 0 805349688 0 906261910 0 596831034 0 578120515 0 62171081 0 789529928 0 771384932 0 205722602 0 403278872 0 815091010 0 ...
output:
3312718818 3861265128 3362893866 3849927844 3835817816 3529816397 3831767697 3442764384 3319076450 3580655078 3232575872 3470604483 3362600128 3236282210 3852519893 3596861437 3328514058 3532992676 3236237839 3822415347 3253045059 3227783088 3420810008 3308716294 3475332002 3376982257 3557234257 357...
result:
ok 66789 numbers
Test #8:
score: 0
Accepted
time: 2134ms
memory: 307036kb
input:
2000000 200000 0 792470592 1 218633397 0 298896984 1 821459817 0 843572367 1 689951951 0 707732711 1 293892369 0 114578208 1 804886090 0 702988189 1 409936527 0 477757270 1 673060920 0 772200189 1 541662721 0 988478996 1 529134354 0 513266838 1 21461785 0 190473673 1 462881268 0 314884037 1 21469307...
output:
3822804675 3409213732 3289393809 3406660553 3505780950 4294967295 3870782256 3558608148 3804270565 4143905727 3912073079 3964046806 3336984723 3741057023 3418012805 4248559615 3776036830 3464510517 3861529949 4294836223 4294930431 4194300927 4294967295 3730488221 3757572095 4278124030 4065485060 367...
result:
ok 66950 numbers
Test #9:
score: 0
Accepted
time: 1054ms
memory: 307780kb
input:
2000000 200000 1 0 0 1 1 2 1 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 1 12 0 13 1 14 1 15 1 16 0 17 1 18 0 19 1 20 1 21 0 22 0 23 0 24 0 25 0 26 0 27 1 28 1 29 0 30 0 31 1 32 1 33 1 34 1 35 1 36 0 37 1 38 0 39 1 40 0 41 1 42 1 43 1 44 0 45 1 46 1 47 0 48 1 49 0 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 0 58 ...
output:
4294367037 4294966783 4293582567 4293762707 4294697407 4294860223 4294369019 4294966175 4294843391 4294170143 4294573979 4294836159 4293880815 4293885887 4294424703 4294775231 4293765213 4294066173 4293869563 4294441983 4294967103 4294843191 4293725215 4294767487 4294962655 4294967275 4294304453 429...
result:
ok 133537 numbers
Test #10:
score: 0
Accepted
time: 749ms
memory: 310076kb
input:
2000000 200000 0 195497456 0 290581042 0 371514487 0 50559621 0 474396829 0 304239719 0 860898164 0 83610030 0 348893942 0 761810777 0 698509278 0 524762309 1 821619833 0 766270119 0 21574565 0 441407189 1 517816135 0 195600505 0 330872740 1 894148434 0 602395873 0 876484788 0 130053814 0 827760932 ...
output:
3559303552 4118049314 4152299556 3713469189 3253954817 3236199174 4031101050 3294899474 3427734368 3479402529 3286285667 3296425223 3323048628 3303378722 3325316443 3572903809 3310712995 3710850114 3441501425 3326681269 3401384411 3964434442 3512986676 3880548788 3838291205 3762890892 3764681099 356...
result:
ok 186846 numbers
Test #11:
score: 0
Accepted
time: 520ms
memory: 307332kb
input:
2000000 200000 0 440685411 0 855977535 0 117492998 0 658205926 0 420756149 0 220632091 0 823536943 0 493591919 0 392682957 0 212193811 0 536783203 0 29448369 0 741146022 0 134097937 0 247254050 1 927213093 0 991955970 0 683742058 0 401736261 0 120047157 0 479316036 0 574921781 0 484430997 0 23510782...
output:
3870165711 3295617128 3846393574 4255448775 3803299543 3827549792 3712760263 3827405543 3827549792 3827405543 3357883335 3357883335 3336687224 3827549792 3422304751 3693417639 3422304751 3358898937 3344313210 3827405543 3827405543 3712760263 3422304751 3712760263 3422304751 3693417639 3827405543 333...
result:
ok 179993 numbers
Test #12:
score: 0
Accepted
time: 813ms
memory: 310316kb
input:
2000000 200000 1 558501328 0 144877333 0 167760550 1 451006701 0 915349366 0 569925011 0 894306307 0 486892561 0 286627949 0 487896610 1 681682730 0 768058963 0 706105703 0 682485350 0 196254528 0 948707203 1 985533226 0 632407715 0 118303817 0 477041692 0 282614642 1 856637759 0 14487688 1 28867357...
output:
4277478863 3350680333 3307420038 3221518621 3291208253 4014304349 3229384339 3307420038 3497886977 3563418555 3580132414 3324869439 3697368839 3328520539 3706170015 3468783423 3344727389 4047355836 4047355836 4047355836 4251792748 3702370214 3296312711 3228437831 3504819615 3329652639 3626448669 409...
result:
ok 100078 numbers