QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#646267#7449. rgxsxrsDaiRuiChen007Compile Error//C++172.8kb2024-10-16 22:00:012024-10-16 22:00:05

Judging History

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

  • [2024-10-16 22:00:05]
  • 评测
  • [2024-10-16 22:00:01]
  • 提交

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];
array<ll,H> sum[MAXS];
void blk_psu(int o,int p) {
	mn[p].fill(inf),mx[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];
	}
}
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];
	}
}
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 psd(int p) {
	if(id[p]) return blk_psd(id[p],p);
	for(int x=0;x<H;++x) if(tg[p][x]) {
		tg[p<<1][x]+=tg[p][x],tg[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=blk(k);x<H;++x) tg[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

answer.code: In function ‘void upd(int, int, int, int, int, int)’:
answer.code:66:35: error: ‘blk’ was not declared in this scope; did you mean ‘vblk’?
   66 |                         for(int x=blk(k);x<H;++x) tg[p][x]+=k;
      |                                   ^~~
      |                                   vblk