QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#865821#9727. Barkley IIIPurslane#WA 1ms9956kbC++142.7kb2025-01-21 23:40:102025-01-21 23:40:11

Judging History

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

  • [2025-01-21 23:40:11]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9956kb
  • [2025-01-21 23:40:10]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ffor(i,a,b) for(int i=(a);i<=(b);i++)
#define roff(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const int MAXN=1e6+10;
int n,q,al,a[MAXN],v1[MAXN<<2],v2[MAXN<<2],tag[MAXN<<2];
#define lson (k<<1)
#define rson (k<<1|1)
#define mid (l+r>>1)
void assign(int k,int l,int r,int v) {tag[k]&=v;if(l!=r) v1[k]&=v,v2[k]&=v;return ;}
void push_down(int k,int l,int r) {return assign(lson,l,mid,tag[k]),assign(rson,mid+1,r,tag[k]),tag[k]=al,void();}
void update(int k,int l,int r,int x,int y,int v) {
	if(x<=l&&r<=y) return assign(k,l,r,v);
	push_down(k,l,r);
	if(x<=mid) update(lson,l,mid,x,y,v);
	if(y>mid) update(rson,mid+1,r,x,y,v);
	return v1[k]=v1[lson]&v1[rson],v2[k]=(v1[lson]&v2[rson])|(v2[lson]&v1[rson]),void();
}
pair<int,int> query(int k,int l,int r,int x,int y) {
	if(x<=l&&r<=y) return {v1[k],v2[k]};
	push_down(k,l,r);
	if(y<=mid) return query(lson,l,mid,x,y);
	if(x>mid) return query(rson,mid+1,r,x,y);
	auto info1=query(lson,l,mid,x,y),info2=query(rson,mid+1,r,x,y);
	return {info1.first&info2.first,(info1.first&info2.second)|(info1.second&info2.first)};
}
void build(int k,int l,int r) {
	tag[k]=al;
	if(l==r) return v1[k]=a[l],v2[k]=al,void();	
	build(lson,l,mid),build(rson,mid+1,r);
	return v1[k]=v1[lson]&v1[rson],v2[k]=(v1[lson]&v2[rson])|(v2[lson]&v1[rson]),void();
}
int bfind(int k,int l,int r,int x,int y,int hp) {
	if(r<x||y<l) return -1;
	if(x<=l&&r<=y) {
		if(v1[k]&hp) return -1;
		if(l==r) return l;
	}
	push_down(k,l,r);
	int ans=bfind(lson,l,mid,x,y,hp);
	if(ans!=-1) return ans;
	return bfind(rson,mid+1,r,x,y,hp);
}
void modify(int k,int l,int r,int pos,int v) {
	if(l==r) return v1[k]=v,v2[k]=al,void();
	push_down(k,l,r);
	if(pos<=mid) modify(lson,l,mid,pos,v);
	else modify(rson,mid+1,r,pos,v);
	return v1[k]=v1[lson]&v1[rson],v2[k]=(v1[lson]&v2[rson])|(v2[lson]&v1[rson]),void();
}
signed main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>q;
	ffor(i,1,n) cin>>a[i];
	ffor(i,0,62) al+=(1ll<<i);
	build(1,1,n);
	ffor(i,1,q) {
		int op;
		cin>>op;
		if(op==1) {
			int l,r,v;
			cin>>l>>r>>v;
			update(1,1,n,l,r,v);	
		}
		if(op==2) {
			int s,x;	
			cin>>s>>x;
			modify(1,1,n,s,x);
		}
		if(op==3) {
			int l,r;
			cin>>l>>r;
			auto pr=query(1,1,n,l,r);
			if(pr.second==0) cout<<0<<'\n';
			else {
				int pos=-1;
				roff(i,62,0) if((pr.first&(1ll<<i))!=(pr.second&(1ll<<i))) {
					pos=(1ll<<i);
					break ;
				}
				if(pos==-1) cout<<pr.first<<'\n';
				else {
					int POS=bfind(1,1,n,l,r,pos);
					int ans=al;
					if(l!=POS) ans&=query(1,1,n,l,POS-1).first;
					if(r!=POS) ans&=query(1,1,n,POS+1,r).first;
					cout<<ans<<'\n';
				}
			}
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 9832kb

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
36134350408385536
1568091718842717482
8795942500783873690

result:

wrong answer 2nd lines differ - expected: '35184908959744', found: '36134350408385536'