QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#300219#4405. 普罗霍洛夫卡Iratis100 ✓7317ms70124kbC++143.2kb2024-01-07 21:22:122024-01-07 21:22:12

Judging History

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

  • [2024-01-07 21:22:12]
  • 评测
  • 测评结果:100
  • 用时:7317ms
  • 内存:70124kb
  • [2024-01-07 21:22:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
using namespace std;
const int MAXN=4e5;
const int blk_sz=256;
const int LOG_B=8;
int n,qu,lst[MAXN+5],a[MAXN+5],bel[MAXN+5],dep[blk_sz*2+5],rev[blk_sz+5];
int res[MAXN+5],ql[MAXN+5],qr[MAXN+5];
vector<pii>qv[MAXN+5];
struct block{
	int L,R,len,b[blk_sz+5],c[2][blk_sz+5],tag,tot_xor[2];
	int coef[blk_sz+5],tot[2][blk_sz+5],nw[blk_sz+5];
	vector<int>vec[blk_sz+2];
	void trans(int *f,int *g){
		static int A[blk_sz*2+5],B[blk_sz*2+5];
		for(int i=0;i<blk_sz;i++)A[rev[i]|blk_sz]=f[i];
		for(int i=blk_sz-1;i;i--)A[i]=A[i<<1]^A[i<<1|1];
		for(int i=1;i<=blk_sz*2-1;i++)B[i]=B[i>>1]^(A[i]<<dep[i]);
		for(int i=0;i<blk_sz;i++)g[i]=B[rev[i]|blk_sz]^(f[i]*(blk_sz*2-1));
	}
	void pushdown(){
		if(!tag)return;
		for(int o=0;o<2;o++){
			trans(tot[o],nw);
			for(int k=1;k<=len;k++)c[o][k]^=nw[b[k]&(blk_sz-1)];
		}
		memset(tot,0,sizeof(tot));
		for(int k=1;k<=len;k++)b[k]+=tag;
		tag=0;
	}
	void rebuild(){
		for(int k=0;k<blk_sz;k++)vec[k].clear();
		for(int k=1;k<=len;k++)vec[b[k]&(blk_sz-1)].pb(k);
		memset(coef,0,sizeof(coef));
		static int tmp[blk_sz+5];
		for(int k=0;k<blk_sz;k++)tmp[k]=vec[k].size()&1;
		trans(tmp,coef);
	}
	void init(){tag=0;rebuild();}
	void add(int tim,int ql,int qr){
		pushdown();
		for(int k=ql;k<=qr;k++){
			c[tim][k]^=(b[k]^(b[k]+1));
			tot_xor[tim]^=(b[k]^(b[k]+1));
			++b[k];
		}
		rebuild();
	}
	void addwhole(int tim){
		int val=(blk_sz-1-tag)&(blk_sz-1);
		tot_xor[tim]^=coef[val];
		tot[tim][val]^=1;
		for(int p:vec[val]){
			c[tim][p]^=(b[p]+tag)^(b[p]+tag+1);
			tot_xor[tim]^=(b[p]+tag)^(b[p]+tag+1);
		}
		tag++;
	}
	int query(int tim,int ql,int qr){
		if(tag)pushdown(),rebuild();
		int res=0;
		for(int k=ql;k<=qr;k++)res^=c[tim][k];
		return res;
	}
	int querywhole(int tim){return tot_xor[tim];}
}B[MAXN/blk_sz+5];
int main(){
//	freopen("in.txt","r",stdin);
	scanf("%d%d",&n,&qu);
	for(int i=0;i<blk_sz;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<(LOG_B-1));
	for(int i=2;i<blk_sz*2;i++)dep[i]=dep[i>>1]+1;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1,l,r;i<=qu;i++){scanf("%d%d",&l,&r);qv[r].pb(mp(l,i));}
	for(int i=1;i<=n;i++)ql[i]=lst[a[i]]+1,qr[i]=i,lst[a[i]]=i;
	int blk_cnt=(n-1)/blk_sz+1;
	for(int i=1;i<=blk_cnt;i++){
		int L=(i-1)*blk_sz+1,R=min(i*blk_sz,n);
		B[i].L=L;B[i].R=R;B[i].len=R-L+1;
		for(int j=L;j<=R;j++)bel[j]=i;
		B[i].init();
	}
	for(int i=1;i<=n;i++){
		int L=ql[i],R=qr[i];
		if(bel[L]==bel[R]){
			B[bel[L]].add(i&1,L-B[bel[L]].L+1,R-B[bel[L]].L+1);
		}else{
			B[bel[L]].add(i&1,L-B[bel[L]].L+1,B[bel[L]].len);
			B[bel[R]].add(i&1,1,R-B[bel[R]].L+1);
			for(int j=bel[L]+1;j<bel[R];j++)B[j].addwhole(i&1);
		}
		for(pii p:qv[i]){
			L=p.fi;R=i;
			if(bel[L]==bel[R]){
				res[p.se]=B[bel[L]].query(i&1,L-B[bel[L]].L+1,R-B[bel[L]].L+1);
			}else{
				res[p.se]^=B[bel[L]].query(i&1,L-B[bel[L]].L+1,B[bel[L]].len);
				res[p.se]^=B[bel[R]].query(i&1,1,R-B[bel[R]].L+1);
				for(int j=bel[L]+1;j<bel[R];j++)res[p.se]^=B[j].querywhole(i&1);
			}
		}
	}
	for(int i=1;i<=qu;i++)printf("%d\n",res[i]);
	return 0;
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 4ms
memory: 38820kb

Test #2:

score: 0
Accepted
time: 6ms
memory: 38984kb

Test #3:

score: 0
Accepted
time: 3ms
memory: 39044kb

Test #4:

score: 0
Accepted
time: 3ms
memory: 39540kb

Test #5:

score: 0
Accepted
time: 0ms
memory: 39828kb

Subtask #2:

score: 5
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 5
Accepted
time: 33ms
memory: 40256kb

Test #7:

score: 0
Accepted
time: 37ms
memory: 38508kb

Test #8:

score: 0
Accepted
time: 36ms
memory: 38312kb

Test #9:

score: 0
Accepted
time: 31ms
memory: 39432kb

Test #10:

score: 0
Accepted
time: 35ms
memory: 39548kb

Subtask #3:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #11:

score: 10
Accepted
time: 1025ms
memory: 46852kb

Test #12:

score: 0
Accepted
time: 1019ms
memory: 47984kb

Test #13:

score: 0
Accepted
time: 1023ms
memory: 47248kb

Test #14:

score: 0
Accepted
time: 1007ms
memory: 46896kb

Test #15:

score: 0
Accepted
time: 1022ms
memory: 46032kb

Subtask #4:

score: 10
Accepted

Dependency #3:

100%
Accepted

Test #16:

score: 10
Accepted
time: 2511ms
memory: 54668kb

Test #17:

score: 0
Accepted
time: 2476ms
memory: 55920kb

Test #18:

score: 0
Accepted
time: 2469ms
memory: 55104kb

Test #19:

score: 0
Accepted
time: 2510ms
memory: 54720kb

Test #20:

score: 0
Accepted
time: 2466ms
memory: 54396kb

Subtask #5:

score: 10
Accepted

Dependency #4:

100%
Accepted

Test #21:

score: 10
Accepted
time: 4442ms
memory: 62252kb

Test #22:

score: 0
Accepted
time: 4437ms
memory: 62340kb

Test #23:

score: 0
Accepted
time: 4430ms
memory: 62532kb

Test #24:

score: 0
Accepted
time: 4443ms
memory: 62248kb

Test #25:

score: 0
Accepted
time: 4452ms
memory: 62376kb

Subtask #6:

score: 10
Accepted

Dependency #5:

100%
Accepted

Test #26:

score: 10
Accepted
time: 5584ms
memory: 66360kb

Test #27:

score: 0
Accepted
time: 5638ms
memory: 66404kb

Test #28:

score: 0
Accepted
time: 5638ms
memory: 66164kb

Test #29:

score: 0
Accepted
time: 5635ms
memory: 66192kb

Test #30:

score: 0
Accepted
time: 5669ms
memory: 66184kb

Subtask #7:

score: 10
Accepted

Test #31:

score: 10
Accepted
time: 70ms
memory: 42784kb

Test #32:

score: 0
Accepted
time: 80ms
memory: 42576kb

Test #33:

score: 0
Accepted
time: 70ms
memory: 42612kb

Test #34:

score: 0
Accepted
time: 66ms
memory: 45252kb

Test #35:

score: 0
Accepted
time: 75ms
memory: 44572kb

Subtask #8:

score: 10
Accepted

Test #36:

score: 10
Accepted
time: 839ms
memory: 53644kb

Test #37:

score: 0
Accepted
time: 825ms
memory: 53676kb

Test #38:

score: 0
Accepted
time: 840ms
memory: 53772kb

Test #39:

score: 0
Accepted
time: 822ms
memory: 53484kb

Test #40:

score: 0
Accepted
time: 826ms
memory: 53812kb

Subtask #9:

score: 10
Accepted

Dependency #8:

100%
Accepted

Test #41:

score: 10
Accepted
time: 868ms
memory: 54564kb

Test #42:

score: 0
Accepted
time: 877ms
memory: 54964kb

Test #43:

score: 0
Accepted
time: 883ms
memory: 55296kb

Test #44:

score: 0
Accepted
time: 851ms
memory: 54956kb

Test #45:

score: 0
Accepted
time: 865ms
memory: 55480kb

Subtask #10:

score: 15
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Dependency #9:

100%
Accepted

Test #46:

score: 15
Accepted
time: 6989ms
memory: 69944kb

Test #47:

score: 0
Accepted
time: 6971ms
memory: 70012kb

Test #48:

score: 0
Accepted
time: 6963ms
memory: 69968kb

Test #49:

score: 0
Accepted
time: 6971ms
memory: 70100kb

Test #50:

score: 0
Accepted
time: 7317ms
memory: 70124kb