QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#646428#7470. WBLTDaiRuiChen0070 39ms16368kbC++173.0kb2024-10-16 23:00:412024-10-16 23:00:43

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 23:00:43]
  • 评测
  • 测评结果:0
  • 用时:39ms
  • 内存:16368kb
  • [2024-10-16 23:00:41]
  • 提交

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,B=32,H=6,pw[H]={1,32,1024,32768,1048576,33554432},MAXS=32785;
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) {
	if(ul<=lp[l]&&rp[r]<=ur) {
		bool flg=1;
		for(int x=vblk(k);x<H;++x) flg&=mn[p][x]-k>=pw[x];
		if(flg) {
			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&((1<<20)-1);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 15864kb

input:

1000
233 991 831 426 140 881 289 287 957 886 561 109 305 469 961 577 683 593 277 601 181 255 100 997 161 619 632 413 987 811 357 635 99 809 888 511 945 881 261 434 851 311 21 641 508 701 661 158 696 560 577 501 951 786 909 238 546 573 617 236 270 705 786 353 651 296 353 720 261 429 855 176 977 57 50...

output:

0 2000000000 0
58536 1 989
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
80551 1 992
0 2000000000 0
28893 5 999
0 2000000000 0
85911 1 996
0 2000000000 0
178822 1 992
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0...

result:

wrong answer 1st numbers differ - expected: '3', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 3ms
memory: 16368kb

input:

100000
241 721 861 909 540 928 171 159 637 60 145 227 110 975 766 220 311 761 191 980 887 793 773 957 625 61 994 606 465 625 598 667 181 197 15 826 136 499 199 331 621 327 945 726 197 997 681 641 465 805 211 531 333 505 483 345 612 241 376 700 5 338 661 777 241 412 118 585 121 1 398 658 855 598 300 ...

output:

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 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
...

result:

wrong answer 1st numbers differ - expected: '2', found: '0'

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 39ms
memory: 16368kb

input:

99917
24947 3268 49683 43610 87927 86331 16017 19557 72137 16689 28231 87819 9481 2403 18661 8145 86091 90410 54635 10896 53999 43367 95987 23733 17359 94625 81763 44331 63663 6075 20784 94229 61578 3890 95047 32681 39491 33139 51629 34573 859 31797 22897 7647 52199 17817 6311 46787 20619 81037 5374...

output:

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 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
0 2000000000 0
...

result:

wrong answer 1st numbers differ - expected: '3', found: '0'