QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#646537 | #7449. rgxsxrs | DaiRuiChen007 | 60 | 1000ms | 24364kb | C++17 | 3.8kb | 2024-10-17 00:30:24 | 2024-10-17 00:30:26 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
namespace IO {
int ow,olim=(1<<23)-100;
char buf[1<<21],*p1=buf,*p2=buf,obuf[1<<23];
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int read() {
int x=0; char c=gc();
while(!isdigit(c)) c=gc();
while(isdigit(c)) x=x*10+(c^48),c=gc();
return x;
}
inline void flush() {
fwrite(obuf,ow,1,stdout),ow=0;
}
inline void write(ll x) {
if(!x) obuf[ow++]='0';
else {
int t=ow;
for(;x;x/=10) obuf[ow++]=(x%10)^48;
reverse(obuf+t,obuf+ow);
}
if(ow>=olim) flush();
}
inline void putc(const char &c) {
obuf[ow++]=c;
if(ow>=olim) flush();
}
#undef gc
}
inline void chkmin(int &x,const int &y) { x=x<y?x:y; }
inline void chkmax(int &x,const int &y) { x=x>y?x:y; }
const int MAXN=5e5+5,inf=2e9,MOD=(1<<20)-1;
const int MAXS=32775,B=31;
const int H=6,pw[]={1,32,1024,32768,1048576,33554432};
inline int vblk(int x) { return upper_bound(pw,pw+H,x)-pw-1; }
int n,m,K,a[MAXN],b[MAXN],lp[MAXN],rp[MAXN],bel[MAXN],id[MAXS];
array<int,H> mn[MAXS],mx[MAXS],tg[MAXS],cnt[MAXS];
array<ll,H> sum[MAXS];
inline void blk_psu(const int &o,const int &p) {
mn[p].fill(inf),mx[p].fill(0),cnt[p].fill(0),sum[p].fill(0);
for(int i=lp[o];i<=rp[o];++i) {
chkmin(mn[p][b[i]],a[i]);
chkmax(mx[p][b[i]],a[i]);
sum[p][b[i]]+=a[i],++cnt[p][b[i]];
}
}
inline void psu(const int &p) {
for(int x=0;x<H;++x) {
mn[p][x]=min(mn[p<<1][x],mn[p<<1|1][x]);
mx[p][x]=max(mx[p<<1][x],mx[p<<1|1][x]);
sum[p][x]=sum[p<<1][x]+sum[p<<1|1][x];
cnt[p][x]=cnt[p<<1][x]+cnt[p<<1|1][x];
}
}
void init(int l=1,int r=K,int p=1) {
if(l==r) return id[p]=l,blk_psu(id[p],p);
int mid=(l+r)>>1;
init(l,mid,p<<1),init(mid+1,r,p<<1|1);
psu(p);
}
void blk_psd(int o,int p) {
for(int i=lp[o];i<=rp[o];++i) if(a[i]>tg[p][b[i]]) a[i]-=tg[p][b[i]];
tg[p].fill(0);
}
void adt(int p,int x,int k) {
if(!cnt[p][x]) return ;
tg[p][x]+=k,mn[p][x]-=k,mx[p][x]-=k,sum[p][x]-=1ll*cnt[p][x]*k;
}
void psd(int p) {
for(int x=0;x<H;++x) if(tg[p][x]) {
adt(p<<1,x,tg[p][x]),adt(p<<1|1,x,tg[p][x]),tg[p][x]=0;
}
}
int qmn,qmx,ul,ur,cl,cr; ll qsum;
inline void blk_qry(const int &o) {
for(int i=max(lp[o],ul);i<=min(rp[o],ur);++i) qsum+=a[i],chkmin(qmn,a[i]),chkmax(qmx,a[i]);
}
void qry(int l=1,int r=K,int p=1) {
if(ul<=lp[l]&&rp[r]<=ur) {
for(int x=0;x<H;++x) qsum+=sum[p][x],chkmin(qmn,mn[p][x]),chkmax(qmx,mx[p][x]);
return ;
}
if(id[p]) return blk_psd(id[p],p),blk_qry(id[p]);
psd(p);
int mid=(l+r)>>1;
if(cl<=mid) qry(l,mid,p<<1);
if(mid<cr) qry(mid+1,r,p<<1|1);
}
inline void blk_upd(const int &k,const int &o) {
for(int i=max(lp[o],ul);i<=min(rp[o],ur);++i) if(a[i]>k) a[i]-=k,b[i]=vblk(a[i]);
}
void upd(const int &k,int l=1,int r=K,int p=1) {
bool fg=1;
for(int x=0;x<H;++x) fg&=mx[p][x]<=k;
if(fg) return ;
if(ul<=lp[l]&&rp[r]<=ur) {
fg=1;
for(int x=vblk(k);x<H;++x) fg&=mn[p][x]-k>=pw[x];
if(fg) {
for(int x=vblk(k);x<H;++x) adt(p,x,k);
return ;
}
}
if(id[p]) return blk_psd(id[p],p),blk_upd(k,id[p]),blk_psu(id[p],p);
psd(p);
int mid=(l+r)>>1;
if(cl<=mid) upd(k,l,mid,p<<1);
if(mid<cr) upd(k,mid+1,r,p<<1|1);
psu(p);
}
signed main() {
ios::sync_with_stdio(false);
n=IO::read(),m=IO::read();
for(int i=1;i<=n;++i) a[i]=IO::read(),b[i]=vblk(a[i]);
K=(n-1)/B+1;
for(int i=1;i<=K;++i) {
lp[i]=(i-1)*B+1,rp[i]=min(i*B,n);
fill(bel+lp[i],bel+rp[i]+1,i);
}
init();
int lst=0;
for(int op,k;m--;) {
op=IO::read(),ul=IO::read()^lst,ur=IO::read()^lst,cl=bel[ul],cr=bel[ur];
if(op==1) k=IO::read()^lst,upd(k);
else {
qmn=inf,qmx=qsum=0,qry();
IO::write(qsum),IO::putc(' ');
IO::write(qmn),IO::putc(' ');
IO::write(qmx),IO::putc('\n');
lst=qsum&MOD;
}
}
IO::flush();
return 0;
}
详细
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 0ms
memory: 20140kb
input:
1000 1000 935816535 513713699 701239859 881761843 312245068 749043434 112422339 4851733 369182510 741607986 336173081 76013815 91837056 23042507 28754006 935721035 332487169 739344582 280604892 549629633 428486579 693745524 772744523 736620619 596867287 553364838 842666116 620926490 350404590 972861...
output:
265016378473 746807 999055631 666065535 666065535 666065535 271006237166 746807 999055631 244146031651 726339 992039812 15823858743 7712227 991422034 1807891893 93288403 840436769 17240518274 746807 968670509 110636754727 726339 817084515 57343541330 746807 806807028 41246731402 746807 770270334 588...
result:
ok 1575 numbers
Subtask #2:
score: 20
Accepted
Test #2:
score: 20
Accepted
time: 81ms
memory: 21508kb
input:
200000 200000 10 7 6 1 5 5 10 1 9 4 7 1 5 4 8 9 5 7 10 2 10 3 3 5 5 2 1 4 10 5 7 2 6 1 3 1 6 4 7 5 3 1 3 2 9 5 4 10 8 3 10 4 4 8 5 4 6 10 4 10 9 6 7 4 6 7 7 6 2 6 6 10 10 6 8 8 9 4 6 3 3 9 8 1 8 5 8 2 7 3 1 10 5 10 1 5 8 5 6 6 7 9 7 3 5 8 4 4 3 2 9 3 10 2 5 4 2 2 6 3 3 5 8 4 2 1 2 9 2 3 6 3 8 9 4 10...
output:
8548 1 10 358083 1 10 371696 1 10 367527 1 10 31930 1 10 41965 1 5 4288 1 10 52736 1 9 311942 1 10 168381 1 10 136991 1 7 52274 1 9 35176 1 5 114387 1 10 4104 1 10 74578 1 6 188927 1 10 425739 1 10 46796 1 6 109184 1 6 47640 1 6 115544 1 6 123196 1 6 118225 1 6 160295 1 5 43007 1 10 10471 1 7 80111 ...
result:
ok 303618 numbers
Test #3:
score: 20
Accepted
time: 80ms
memory: 22272kb
input:
200000 200000 10 9 3 10 4 4 2 5 9 2 8 8 8 9 6 6 2 1 2 9 10 3 2 6 6 7 1 10 9 8 7 10 6 10 2 5 3 5 7 1 1 9 2 3 4 4 7 5 5 9 1 10 9 8 9 7 10 10 5 7 7 4 10 3 9 5 7 5 4 7 3 8 3 1 10 4 7 5 8 1 4 7 1 9 5 4 8 8 1 9 10 3 8 6 5 2 7 7 3 10 5 7 10 6 10 2 8 3 7 7 6 4 1 3 3 9 6 3 1 1 5 9 4 6 5 4 6 5 8 4 5 5 1 5 10 ...
output:
120436 1 10 27918 1 6 11888 1 10 48329 1 6 43608 1 6 151778 1 10 46169 1 6 46361 1 10 483850 1 10 124481 1 10 526839 1 10 119733 1 5 154279 1 10 7638 1 6 3630 1 5 54630 1 5 250280 1 10 123344 1 10 145094 1 6 130966 1 6 34776 1 10 26218 1 3 185021 1 9 28302 1 5 2697 1 10 135625 1 6 67958 1 4 164444 1...
result:
ok 303477 numbers
Test #4:
score: 20
Accepted
time: 60ms
memory: 21356kb
input:
199998 199995 10 4 6 4 4 4 3 5 2 9 5 2 10 9 8 6 7 5 1 6 5 3 7 10 8 5 6 9 2 5 3 8 6 9 5 2 7 2 10 6 1 7 6 3 4 3 9 5 2 4 8 9 1 8 7 4 6 1 10 3 8 7 2 7 1 1 8 3 1 3 2 2 2 3 5 10 5 7 6 10 10 1 8 1 9 7 7 10 3 7 8 6 10 7 6 3 3 10 1 4 2 2 7 9 5 3 1 6 10 10 3 2 10 3 1 6 4 1 3 6 7 2 10 9 8 1 5 1 1 8 6 3 4 3 4 9...
output:
1100462 1 10 1100462 1 10 681018 1 7 681018 1 7 340625 1 4 340629 1 4 340635 1 4 340636 1 4 280123 1 3 280128 1 3 280125 1 3 280127 1 3 280131 1 3 280127 1 3 280134 1 3 280131 1 3 240083 1 2 240082 1 2 240095 1 5 240085 1 2 240090 1 2 240085 1 2 240081 1 2 240085 1 2 240087 1 2 240082 1 2 240082 1 2...
result:
ok 303447 numbers
Subtask #3:
score: 20
Accepted
Test #5:
score: 20
Accepted
time: 107ms
memory: 24036kb
input:
200000 200000 615 736 846 534 658 429 631 720 898 583 797 295 303 336 449 358 57 338 954 414 330 212 171 200 403 553 308 20 805 249 767 291 545 196 324 928 439 197 20 601 737 748 817 858 816 130 403 858 813 936 771 242 833 863 978 260 357 856 954 89 673 733 364 473 903 445 823 894 49 747 382 56 309 ...
output:
4143168 1 1000 8707838 1 1000 47796901 1 1000 55161188 1 1000 17880698 1 1000 9738037 1 888 11217598 1 939 2273447 1 939 12642515 1 888 12437017 1 999 15429733 1 888 29802638 1 939 200711 2 887 51511251 1 1000 9402071 1 888 25821404 1 939 19529749 1 923 6444888 1 930 10956864 1 564 1514736 1 408 881...
result:
ok 303498 numbers
Test #6:
score: 20
Accepted
time: 109ms
memory: 21552kb
input:
200000 200000 125 824 862 182 678 103 976 229 994 666 261 737 199 82 516 546 993 137 824 978 152 110 658 490 260 884 466 658 80 203 193 443 19 931 960 23 631 599 241 535 772 487 972 459 325 180 450 245 625 743 373 110 795 745 877 694 50 259 939 542 544 831 881 600 77 748 527 805 36 348 118 781 452 9...
output:
50865154 1 1000 24220463 1 919 1989344 1 919 3666274 1 697 8844621 1 910 17319620 1 919 13277574 1 760 13369358 1 617 11322496 1 617 5979926 1 755 528498 1 351 3799125 1 351 9939407 1 351 12522427 1 1000 1849238 1 351 938420 1 339 16252281 1 1000 1216964 1 238 40887 1 342 1201726 1 712 3143310 1 351...
result:
ok 303603 numbers
Test #7:
score: 20
Accepted
time: 64ms
memory: 21588kb
input:
199997 199998 3 10 7 6 7 1 7 3 7 2 1 3 5 6 9 6 10 5 9 8 6 3 5 8 1 1 8 1 10 3 9 9 10 6 7 4 5 1 1 9 10 10 6 10 8 3 7 8 4 10 10 4 10 5 4 7 6 3 5 8 8 6 8 9 5 8 6 7 5 7 1 3 7 7 10 6 7 6 10 9 5 4 5 3 6 10 4 3 2 10 8 3 7 10 1 8 9 6 4 7 1 6 8 9 10 7 5 3 2 8 9 4 5 2 8 10 5 1 9 4 8 3 10 5 3 2 1 6 9 8 5 4 2 4 ...
output:
1103927 1 10 199995 1 2 199989 1 1 199995 1 2 199992 1 2 199997 1 2 199997 1 2 199988 1 1 199987 1 1 199992 1 1 199994 1 1 199987 1 1 199988 1 1 199989 1 1 199991 1 1 199994 1 1 199988 1 1 199992 1 1 199990 1 1 199992 1 1 199991 1 1 199998 1 3 199990 1 1 199991 1 1 199987 1 1 199998 1 3 199991 1 1 1...
result:
ok 303471 numbers
Subtask #4:
score: 0
Time Limit Exceeded
Test #8:
score: 20
Accepted
time: 127ms
memory: 24240kb
input:
200000 200000 78066 141247 11068 105207 26127 179253 104948 145839 150954 60877 67556 61673 69638 150806 127596 162902 125410 38242 97645 20582 193537 139906 114184 129867 126626 85640 91551 19445 134855 85251 22162 3798 122992 38278 131907 96159 153440 94561 185234 15296 76886 108452 70560 77355 14...
output:
9335629761 8 199997 291062233 15 145210 2757513812 2 114001 457932161 15 145210 2988949571 2 104377 2096022866 2 145091 51774664 57 104218 1802593096 2 101531 838652514 1 91888 2086037512 5 199981 1740038288 2 113977 2833816579 1 101510 1643368391 2 132714 1457965364 2 101524 868906251 2 101524 8249...
result:
ok 303507 numbers
Test #9:
score: 20
Accepted
time: 121ms
memory: 21500kb
input:
200000 200000 58317 79021 111303 154733 179567 182629 28968 33314 26824 125092 137496 124768 21399 111741 66359 31703 141726 116799 156902 28665 149214 66685 131783 19127 38615 4167 165498 40897 131724 96109 70688 194505 116284 197762 197275 125439 199849 166102 198410 81173 189204 163194 89937 6629...
output:
10985120427 2 200000 14253061393 1 200000 14076919529 1 200000 155392718 18 199663 3863170615 1 199996 434379913 1 195113 4794602467 1 130342 546767600 22 130346 1870193310 1 199971 179334704 16 195113 8677927116 1 130348 106148166 2 130332 960648401 1 117463 2257713113 1 130348 7347437398 1 199939 ...
result:
ok 303558 numbers
Test #10:
score: 0
Time Limit Exceeded
input:
200000 200000 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 ...
output:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #12:
score: 20
Accepted
time: 1000ms
memory: 24364kb
input:
500000 500000 56 22353719 15918 54 13 1 389 7 809 2204 75911688 4218278 36 7205 93542078 506 4761175 102646343 48 65900 10 228 2 292994 26348644 6 19339 148 704 232124395 19307 52070 8964343 7430314 42755 115 869 32485365 252183868 481162087 852632 38758 2945883 279412 15012 82 33076951 1537 6954898...
output:
106593480756 1 984003850 3657321749885 1 772605710 4340368607039 1 997617313 2024546424119 1 999735807 1053708059297 1 999735807 1594458070417 1 999904830 3990648241119 1 772605710 2714488265571 1 999735807 384978298678 1 772605710 1159542455950 1 999273673 3500807088693 1 967123827 5113110257086 1 ...
result:
ok 741759 numbers
Test #13:
score: 0
Time Limit Exceeded
input:
500000 500000 719948 153 112344106 7040 61985682 1 4356 19222 34672195 143174 78 125 40 3164569 5392 441953981 421249543 12617 3266128 328415 53035 94 9 1346009 225 15 59366 45339 5849 2398 27 156152 2638 4843 26647250 11247481 329 214049 894418 3236 208 1 484 238 8994209 369935 86558 40 221409788 1...