QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#855826#9727. Barkley IIIyhdddWA 2ms11996kbC++203.6kb2025-01-13 11:25:582025-01-13 11:25:58

Judging History

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

  • [2025-01-13 11:25:58]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11996kb
  • [2025-01-13 11:25:58]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=1000010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,q,a[maxn];
#define mid (l+r>>1)
#define ls nd<<1
#define rs nd<<1|1
#define all ((1ll<<63)-1)
pii tree[maxn<<2];int tag[maxn<<2];
int pl[maxn<<2],pr[maxn<<2];
pii merge(pii u,pii v){
	return {(u.fi&v.se)|(u.se&v.fi),u.se&v.se};
}
void build(int nd,int l,int r){
	tag[nd]=all;pl[nd]=l,pr[nd]=r;
	if(l==r){
		tree[nd]={all^a[l],a[l]};
		return ;
	}
	build(ls,l,mid),build(rs,mid+1,r);
	tree[nd]=merge(tree[ls],tree[rs]);
}
void upd(int nd,int w){
	tree[nd].fi&=w,tree[nd].se&=w,tag[nd]&=w;
	if(pl[nd]==pr[nd])tree[nd].fi=all^tree[nd].se;
}
void down(int nd){
	upd(ls,tag[nd]),upd(rs,tag[nd]),tag[nd]=all;
}
void updata(int nd,int l,int r,int ql,int qr,int w){
	if(l>=ql&&r<=qr)return upd(nd,w);
	if(tag[nd]!=all)down(nd);
	if(ql<=mid)updata(ls,l,mid,ql,qr,w);
	if(qr>mid)updata(rs,mid+1,r,ql,qr,w);
	tree[nd]=merge(tree[ls],tree[rs]);
}
void modif(int nd,int l,int r,int p,int w){
	if(l==r){
		tree[nd]={all^w,w};
		return ;
	}
	if(tag[nd]!=all)down(nd);
	if(p<=mid)modif(ls,l,mid,p,w);
	else modif(rs,mid+1,r,p,w);
	tree[nd]=merge(tree[ls],tree[rs]);
	// cout<<l<<" "<<r<<" "<<tree[nd].fi<<" "<<tree[nd].se<<" "<<tree[ls].fi<<" "<<tree[rs].se<<"\n";
}
pii query(int nd,int l,int r,int ql,int qr){
	if(l>=ql&&r<=qr)return tree[nd];
	if(tag[nd]!=all)down(nd);
	if(qr<=mid)return query(ls,l,mid,ql,qr);
	if(ql>mid)return query(rs,mid+1,r,ql,qr);
	return merge(query(ls,l,mid,ql,qr),query(rs,mid+1,r,ql,qr));
}
int ask(int nd,int l,int r,int ql,int qr){
	if(ql>qr)return all;
	if(l>=ql&&r<=qr)return tree[nd].se;
	if(tag[nd]!=all)down(nd);
	if(qr<=mid)return ask(ls,l,mid,ql,qr);
	if(ql>mid)return ask(rs,mid+1,r,ql,qr);
	return ask(ls,l,mid,ql,qr)&ask(rs,mid+1,r,ql,qr);
}
int fd(int p,int w){
	int nd=1,l=1,r=n;
	while(l!=r){
		if(tag[nd]!=all)down(nd);
		if(p<=mid)nd=ls,r=mid;
		else nd=rs,l=mid+1;
	}
	pii val=tree[nd];
	if(val.fi&(1ll<<w))return l;
	while(nd){
		nd>>=1,l=pl[nd],r=pr[nd];
		pii res=val;
		if(p<=mid)res=merge(val,tree[rs]);
		if(!(res.fi&(1ll<<w)))val=res;
		else break;
	}
	nd=rs,l=pl[nd],r=pr[nd];
	// cout<<l<<" "<<r<<" "<<val.fi<<" "<<val.se<<"\n";
	while(l!=r){
		if(tag[nd]!=all)down(nd);
		pii res=merge(val,tree[ls]);
		if(res.fi&(1ll<<w))nd=ls,r=mid;
		else val=res,nd=rs,l=mid+1;
	}
	return l;
}
void work(){
	n=read();q=read();
	for(int i=1;i<=n;i++)a[i]=read();
	build(1,1,n);
	while(q--){
		// cout<<tree[8].fi<<" "<<tree[8].se<<" q\n";
		int op=read();
		if(op==1){
			int l=read(),r=read(),x=read();
			updata(1,1,n,l,r,x);
		}
		if(op==2){
			int p=read(),x=read();
			modif(1,1,n,p,x);
		}
		if(op==3){
			int l=read(),r=read(),ans=0;
			pii res=query(1,1,n,l,r);
			// cout<<res.fi<<" "<<res.se<<"\n";
			for(int i=62;~i;i--)if(res.fi&(1ll<<i)){
				int p=fd(l,i);
				// cout<<i<<" "<<p<<"\n";
				ans=ask(1,1,n,l,p-1)&ask(1,1,n,p+1,r);
				break;
			}
			if(!ans)ans=res.se;
			printf("%lld\n",ans);
		}
	}
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 9
7 7 7 6 7
3 1 5
2 1 3
3 1 5
3 1 3
1 1 2 3
3 1 3
2 2 8
3 1 3
3 1 2

output:

7
6
7
3
3
8

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 11948kb

input:

10 10
6760061359215711796 1568091718842717482 1568091718842717482 1568091718842717482 5232472783634052627 8795942500783873690 1568091718842717482 1568091718842717482 1568091718842717482 1568091718842717482
1 3 5 7587422031989082829
3 6 10
1 7 8 5197616143400216932
2 4 2518604563805514908
2 2 4533959...

output:

1568091718842717482
35184908959744
176025477579040
8795942500783873690

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 11984kb

input:

100 100
4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 625967318191814868 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072...

output:

70368744177664
1
0
4263579105072360993
1306043896232411137
4263579105072360993
70368744177664
77309673472
0
1153488865559840256
0
1730020640668059136
3533641810948498945
67108864
1730020640668059136
0
77309673472
1729382296723653632
0
1730020640668059136
3533641810948498945
0
562949953683456
1730020...

result:

wrong answer 1st lines differ - expected: '576531121047601152', found: '70368744177664'