QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#152525#6427. Just Another Game of Stonesqzez#WA 363ms78068kbC++142.7kb2023-08-28 11:03:362023-08-28 11:03:37

Judging History

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

  • [2023-08-28 11:03:37]
  • 评测
  • 测评结果:WA
  • 用时:363ms
  • 内存:78068kb
  • [2023-08-28 11:03:36]
  • 提交

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.x=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;
		} 
		f[v].x=w2;t[v]=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(x<=l&&r<=y&&z<f[v].y) return PF(v,f[v].x,z);P(v);
		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: 2ms
memory: 8072kb

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: 363ms
memory: 78068kb

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
-365771968
46013
-401789054
29322
-1729542763
1605
572
4908
80609186
1225593457
-164257860
1590949349
7231
1797101889
-1299258602
-1773747026
7464
-2100724068
21
784533537
-360879433
733053175
1791071597
666221630
-1186087755
-1321591554
-1886364297
1699478780
-2083755849
621925943
1649648815
...

result:

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