QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#744262#9727. Barkley IIISylviallineWA 1ms5648kbC++232.5kb2024-11-13 21:22:162024-11-13 21:22:17

Judging History

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

  • [2025-01-13 03:55:43]
  • hack成功,自动添加数据
  • (/hack/1447)
  • [2024-11-13 21:22:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5648kb
  • [2024-11-13 21:22:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve();
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
	// cin>>t;
	while(t--)solve();
}
const int N=1e6+3;
struct node{
	ll s,t,w,lz;
	bool isleaf;
	inline void init(ll x){
		s=lz=-1;
		t=~x;
		w=x;
	}
	inline void cover(ll x){
		w&=x;
		if(isleaf)t=~w;
		else{
			lz&=x;
			s&=x;
		}
	}
	inline friend node merge(const node &a,const node &b){
		return {a.s&b.s&~(a.t&b.t),a.t^b.t,a.w&b.w,-1};
	}
	
}T[N<<2];

void pushdown(int p){
	if(T[p].lz==-1)return;
	T[p<<1].cover(T[p].lz);
	T[p<<1|1].cover(T[p].lz);
	T[p].lz=-1;
}
inline void update(int p){
	T[p]=merge(T[p<<1],T[p<<1|1]);
}
#define pL p<<1,l,mid
#define pR p<<1|1,mid+1,r

ll a[N];
void build(int p,int l,int r){
	if(l==r){
		T[p].init(a[l]);
		T[p].isleaf=1;
		return;
	}
	int mid=l+r>>1;
	build(pL);
	build(pR);
	update(p);
}
void modify(int p,int l,int r,int x){
	if(l==r){
		T[p].init(a[l]);
		return;
	}
	pushdown(p);
	int mid=l+r>>1;
	if(mid>=x)modify(pL,x);
	else modify(pR,x);
	update(p);
}
void iand(int p,int l,int r,int x,int y,ll d){
	if(l>=x&&r<=y){
		T[p].cover(d);
		return;
	}
	pushdown(p);
	int mid=l+r>>1;
	if(mid>=x)iand(pL,x,y,d);
	if(mid<y)iand(pR,x,y,d);
	update(p);
}
node obtain(int p,int l,int r,int x,int y){
	if(l>=x&&r<=y)return T[p];
	pushdown(p);
	int mid=l+r>>1;
	if(mid>=y)return obtain(pL,x,y);
	if(mid<x)return obtain(pR,x,y);
	return merge(obtain(pL,x,y),obtain(pR,x,y));
}
int find(int p,int l,int r,int x,int y,int k){
	if(l==r)return l;
	pushdown(p);
	int mid=l+r>>1;
	if(l>=x&&r<=y){
		if(T[p].w>>k&1)return -1;
		if(T[p<<1].w>>k&1)return find(pR,x,y,k);
		return find(pL,x,y,k);
	}
	if(mid>=y)return find(pL,x,y,k);
	if(mid<x)return find(pR,x,y,k);
	return max(find(pL,x,y,k),find(pR,x,y,k));
}


void solve(){
	int n,q;
	cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>a[i];
	build(1,1,n);
	while(q--){
		int op;
		cin>>op;
		if(op==1){
			int l,r;ll x;
			cin>>l>>r>>x;
			iand(1,1,n,l,r,x);
		}
		if(op==2){
			int s;ll x;
			cin>>s>>x;
			a[s]=x;
			modify(1,1,n,s);
		}
		if(op==3){
			int l,r;cin>>l>>r;
			node z=obtain(1,1,n,l,r);
			ll u=z.s&z.t,ans;
			auto func=[&](int l,int r){
				if(l>r)return -1ll;
				return obtain(1,1,n,l,r).w;
			};
			if(u==0)ans=z.w;
			else{
				int k=-1;
				for(;u;u>>=1)++k;
				int pos=find(1,1,n,l,r,k);
				ans=func(l,pos-1)&func(pos+1,r);
			}
			cout<<ans<<endl;
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 1ms
memory: 5640kb

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
986444436075452520

result:

wrong answer 4th lines differ - expected: '8795942500783873690', found: '986444436075452520'