QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#646446 | #7449. rgxsxrs | DaiRuiChen007 | 20 | 3003ms | 18168kb | C++17 | 3.1kb | 2024-10-16 23:09:28 | 2024-10-16 23:09:29 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
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=32785,B=32;
const int H=6,pw[]={1,32,1024,32768,1048576,33554432};
inline int vblk(int x) { return upper_bound(pw,pw+6,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];
void blk_psu(int o,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]];
}
}
void psu(int p) {
if(id[p]) return blk_psu(id[p],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]=sum[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]],assert(a[i]>=pw[b[i]]);
tg[p].fill(0);
}
void adt(int p,int x,int k) {
tg[p][x]+=k,mn[p][x]-=k,mx[p][x]-=k,sum[p][x]-=1ll*cnt[p][x]*k;
}
void psd(int p) {
if(id[p]) return blk_psd(id[p],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; ll qsum;
void blk_qry(int l,int r,int o) {
for(int i=max(lp[o],l);i<=r&&i<=rp[o];++i) qsum+=a[i],chkmin(qmn,a[i]),chkmax(qmx,a[i]);
}
void qry(int ul,int ur,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 ;
}
psd(p);
if(id[p]) return blk_qry(ul,ur,id[p]);
int mid=(l+r)>>1;
if(bel[ul]<=mid) qry(ul,ur,l,mid,p<<1);
if(mid<bel[ur]) qry(ul,ur,mid+1,r,p<<1|1);
}
void blk_upd(int l,int r,int k,int o) {
for(int i=max(lp[o],l);i<=r&&i<=rp[o];++i) if(a[i]>k) a[i]-=k,b[i]=vblk(a[i]);
}
void upd(int ul,int ur,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 ;
}
}
psd(p);
if(id[p]) return blk_upd(ul,ur,k,id[p]),blk_psu(id[p],p);
int mid=(l+r)>>1;
if(bel[ul]<=mid) upd(ul,ur,k,l,mid,p<<1);
if(mid<bel[ur]) upd(ul,ur,k,mid+1,r,p<<1|1);
psu(p);
}
signed main() {
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=n;++i) cin>>a[i],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,l,r,k;m--;) {
cin>>op>>l>>r,l^=lst,r^=lst;
if(op==1) cin>>k,k^=lst,upd(l,r,k);
else {
qmn=inf,qmx=qsum=0,qry(l,r);
cout<<qsum<<" "<<qmn<<" "<<qmx<<"\n";
lst=qsum&MOD;
}
}
return 0;
}
详细
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 0ms
memory: 16024kb
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: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 798ms
memory: 16780kb
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 371526 1 10 380188 1 10 0 2000000000 0 132190 1 7 15123 1 9 91015 1 10 0 2000000000 0 0 2000000000 0 0 2000000000 0 27827 1 10 70625 1 9 0 2000000000 0 0 2000000000 0 102160 1 10 0 2000000000 0 0 2000000000 0 0 2000000000 0 185252 1 10 0 2000000000 0 405989 1 10 0 2000000000 0 ...
result:
wrong answer 7th numbers differ - expected: '371696', found: '371526'
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 791ms
memory: 16780kb
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 6702012 1 939 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0...
result:
wrong answer 19th numbers differ - expected: '11217598', found: '6702012'
Subtask #4:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 1028ms
memory: 16716kb
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:
wrong answer 547th numbers differ - expected: '464169781', found: '-910829851'
Subtask #5:
score: 0
Wrong Answer
Test #12:
score: 0
Wrong Answer
time: 3003ms
memory: 18168kb
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 -100849655247298824 1 772605710 0 2000000000 0 1752665290570 1 772166124 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 2000000000 0 0 20000...
result:
wrong answer 4th numbers differ - expected: '3657321749885', found: '-100849655247298824'