QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#762412#9727. Barkley IIILinxWA 2ms11924kbC++233.6kb2024-11-19 14:54:362024-11-19 14:54:37

Judging History

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

  • [2025-01-13 03:55:43]
  • hack成功,自动添加数据
  • (/hack/1447)
  • [2024-11-19 14:54:37]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11924kb
  • [2024-11-19 14:54:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
int n,q,opt,l,r,p;
ll a[maxn],x;
const ll M=(1ll<<62)-1+(1ll<<62);
ll nowop,nowall,nowsum;
ll sum[maxn<<2],op[maxn<<2],all[maxn<<2],lazy[maxn<<2];
void pushup(int rt) {
	sum[rt]=(sum[rt<<1]&sum[rt<<1|1]);
	op[rt]=(op[rt<<1]&all[rt<<1|1])|(op[rt<<1|1]&all[rt<<1]);
	all[rt]=all[rt<<1]&all[rt<<1|1];
}
void build(int rt,int l,int r) {
	lazy[rt]=-1;
	if(l==r) {
		op[rt]=(a[l]^M);
		all[rt]=a[l];
		sum[rt]=a[l];
		return;
	}
	int mid=l+r>>1;
	build(rt<<1,l,mid);
	build(rt<<1|1,mid+1,r);
	pushup(rt);
}
void pushdown(int rt,int l,int r) {
	if(lazy[rt]!=-1) {
		ll x=lazy[rt];
		lazy[rt]=-1;
		if(lazy[rt<<1]==-1) lazy[rt<<1]=x;
		else lazy[rt<<1]&=x;
		if(lazy[rt<<1|1]==-1) lazy[rt<<1|1]=x;
		else lazy[rt<<1|1]&=x;
		sum[rt<<1]&=x,sum[rt<<1|1]&=x;
		all[rt<<1]&=x,all[rt<<1|1]&=x;
		int mid=l+r>>1;
		if(mid-l+1==1) op[rt<<1]=sum[rt<<1]^M;
		else op[rt<<1]&=x;
		if(r-mid==1) op[rt<<1|1]=sum[rt<<1|1]^M;
		else op[rt<<1|1]&=x;
	}
}
void update(int rt,int l,int r,int L,int R,int x) {
	if(L<=l&&R>=r) {
		sum[rt]&=x;
		all[rt]&=x;
		if(lazy[rt]==-1) lazy[rt]=x;
		else lazy[rt]&=x;
		if(r-l+1==1) op[rt]=sum[rt]^M;
		else op[rt]&=x;
		return;
	}
	pushdown(rt,l,r);
	int mid=l+r>>1;
	if(L<=mid) update(rt<<1,l,mid,L,R,x);
	if(R>mid) update(rt<<1|1,mid+1,r,L,R,x);
	pushup(rt);
}
void change(int rt,int l,int r,int p,ll x) {
	if(l==r) {
		op[rt]=(x^M);
		all[rt]=x;
		sum[rt]=x;
		return;
	}
	pushdown(rt,l,r);
	int mid=l+r>>1;
	if(p<=mid) change(rt<<1,l,mid,p,x);
	else change(rt<<1|1,mid+1,r,p,x);
	pushup(rt);
}
void query(int rt,int l,int r,int L,int R) {
    //if(L==1&&R==2) printf("%d %d %lld\n",l,r,op[rt]);
	if(L<=l&&R>=r) {
		nowop=(nowop&all[rt])|(op[rt]&nowall);
		nowsum&=sum[rt];
		nowall&=all[rt];
		return;
	}
	pushdown(rt,l,r);
	int mid=l+r>>1;
	if(L<=mid) query(rt<<1,l,mid,L,R);
	if(R>mid) query(rt<<1|1,mid+1,r,L,R);
	pushup(rt);
}
int pos;
void find(int rt,int l,int r,int L,int R,ll x) {
	if(pos) return;
    if(L<=l&&R>=r) {
        if(l==r) {
            if(op[rt]&x) pos=l;
            return;
        }
        pushdown(rt,l,r);
        int mid=l+r>>1;
        if(pos==0&&(op[rt<<1]&x)) find(rt<<1,l,mid,L,R,x);
        if(pos==0&&(op[rt<<1|1]&x)) find(rt<<1|1,mid+1,r,L,R,x);
        pushup(rt);
        return;
    }
	if(l==r) {
		pos=l;
		return;
	}
    pushdown(rt,l,r);
    //if(L==1&&R==2) printf("%d %d %lld %lld\n",l,r,op[rt<<1],op[rt<<1|1]);
	int mid=l+r>>1;
	if(pos==0&&L<=mid) find(rt<<1,l,mid,L,R,x);
	if(pos==0&&R>mid) find(rt<<1|1,mid+1,r,L,R,x);
	pushup(rt);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;++i) cin>>a[i];
	build(1,1,n);
	while(q--) {
		cin>>opt;
		if(opt==1) {
			cin>>l>>r>>x;
			update(1,1,n,l,r,x);
		}
		else if(opt==2) {
			cin>>p>>x;
			change(1,1,n,p,x);
		}
		else {
			cin>>l>>r;
			nowall=nowsum=M,nowop=0;
			query(1,1,n,l,r);
			//printf("!!! %lld\n",nowop);
			if(nowop==0) {
				nowall=nowsum=M,nowop=0;
				query(1,1,n,l,r-1);
				cout<<nowsum<<'\n';
			}
			else {
				int now=-1;
				while(nowop) now++,nowop>>=1;
                //printf("qwq %d\n",now);
				pos=0,find(1,1,n,l,r,1ll<<now);
                //printf("%d\n",pos);
				ll ans=M;
				if(l<pos) {
					nowall=nowsum=M,nowop=0;
					query(1,1,n,l,pos-1);
					ans&=nowsum;
				}
				if(pos<r) {
					nowall=nowsum=M,nowop=0;
					query(1,1,n,pos+1,r);
					ans&=nowsum;
				}
				cout<<ans<<'\n';
			}
		}
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 11788kb

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

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
536870912
537919776
8795942500783873690

result:

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