QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#152533#6427. Just Another Game of Stonesqzez#WA 308ms77428kbC++142.7kb2023-08-28 11:11:002023-08-28 11:11:01

Judging History

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

  • [2023-08-28 11:11:01]
  • 评测
  • 测评结果:WA
  • 用时:308ms
  • 内存:77428kb
  • [2023-08-28 11:11:00]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=2e5+5,M=N*4+5,K=(1<<15)+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=2e9+7;mt19937 rnd(time(0));
int n,m,A[N];
struct Node{
	int x,y,w;
	Node operator +(const Node &B)const{
		Node C;
		if(x<B.x) C.x=x,C.w=w;
		else if(x>B.x) C.x=B.x,C.w=B.w;
		else C.x=x,C.w=w+B.w;
		C.y=INF;
		if(x^C.x) C.y=min(C.y,x);
		if(y^C.x) C.y=min(C.y,y);
		if(B.x^C.x) C.y=min(C.y,B.x);
		if(B.y^C.x) C.y=min(C.y,B.y);
		return C;
	}
};
namespace Tree{
	#define ls v<<1
	#define rs v<<1|1
	Node f[M];
	int t[M];
	int g[M][30];
	void Up(int v){
		f[v]=f[ls]+f[rs];
		for(int i=0;i<30;i++) g[v][i]=g[ls][i]+g[rs][i];
	}
	void PF(int v,int w1,int w2){
		if(w1^f[v].x) return;
		for(int i=0;i<30;i++){
			if(f[v].x>>i&1) g[v][i]-=f[v].w;
			if(w2>>i&1) g[v][i]+=f[v].w;
		} 
		if(t[v]==-1) t[v]=w1;
		f[v].x=w2;
	}
	void P(int v){
		if(~t[v]) PF(ls,t[v],f[v].x),PF(rs,t[v],f[v].x),t[v]=-1;
	}
	void BD(int l=1,int r=n,int v=1){
		t[v]=-1;
		if(l==r){
			f[v]=(Node){A[l],INF,1};
			for(int i=0;i<30;i++) if(f[v].x>>i&1) g[v][i]++;
			return;
		}
		int m=l+r>>1;BD(l,m,ls);BD(m+1,r,rs);Up(v);
	}
	void Add(int x,int y,int z,int l=1,int r=n,int v=1){
		if(f[v].x>=z) return;if(l^r) P(v);
		if(x<=l&&r<=y&&z<f[v].y) return PF(v,f[v].x,z);
		int m=l+r>>1;x<=m&&(Add(x,y,z,l,m,ls),0);y>m&&(Add(x,y,z,m+1,r,rs),0);Up(v);
	}
	int qry(int x,int y,int l=1,int r=n,int v=1){
		if(x<=l&&r<=y) {
			int ans=0;for(int i=0;i<30;i++) if(g[v][i]&1) ans|=1<<i;
			return ans;
		}
		int m=l+r>>1;P(v);
		return (x<=m?qry(x,y,l,m,ls):0)+(y>m?qry(x,y,m+1,r,rs):0);
	}
	int find(int x,int y,int z,int l=1,int r=n,int v=1){
		if(x<=l&&r<=y) return g[v][z];int m=l+r>>1;P(v);
		return (x<=m?find(x,y,z,l,m,ls):0)+(y>m?find(x,y,z,m+1,r,rs):0);
	}
}
void Solve(){
	int i,j;scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++) scanf("%d",&A[i]);
	int k=m;Tree::BD();
	while(m--){
		int op,l,r,x;scanf("%d%d%d%d",&op,&l,&r,&x);
		if(op==1){
			Tree::Add(l,r,x);
		}else{
			int tot=x^Tree::qry(l,r);
			if(!tot){puts("0");continue;}
			// int ans=0,y=__lg(tot);for(i=l;i<=r;i++) if(A[i]>>y&1) ans++;ans+=(x>>y&1);
			int y=__lg(tot);
			printf("%d\n",(x>>y&1)+Tree::find(l,r,y));
		}
	}
}
int main(){
	int t;
	// scanf("%d",&t);
	t=1;
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}


详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 7976kb

input:

5 4
1 2 1 4 1
2 1 3 1
1 2 4 3
2 2 4 4
2 1 4 4

output:

1
0
3

result:

ok 3 number(s): "1 0 3"

Test #2:

score: -100
Wrong Answer
time: 308ms
memory: 77428kb

input:

200000 200000
962352030 173642520 1008864183 74920228 684681800 500911321 1001441054 257633652 185843534 59168654 317689197 731348417 123888883 708119712 340055368 876566011 980078202 969174443 814012870 715639041 596932238 173757742 314504576 1045746913 740811577 570187156 999816627 12441059 122507...

output:

38900
63867
45905
20129
29322
128692
1444
661
4001
25192
347
12263
879
5176
15800
20589
97277
16733
7690
21
31618
25031
41465
12170
59739
36277
19825
15479
49220
21551
896
729
4833
50495
49193
22495
137
178
9136
25369
1681
30674
39783
111237
39978
42830
61259
43000
41454
101821
14527
57808
75859
211...

result:

wrong answer 1st numbers differ - expected: '38889', found: '38900'