QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#375826#6631. Maximum Bitwise ORWorld_CreaterWA 130ms54872kbC++142.2kb2024-04-03 16:16:492024-04-03 16:16:50

Judging History

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

  • [2024-04-03 16:16:50]
  • 评测
  • 测评结果:WA
  • 用时:130ms
  • 内存:54872kb
  • [2024-04-03 16:16:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,q,a[100005],f[100005][31],lst[100005][31];
int lis[35],idx;
struct segtree{
	int tree[400005];
	#define lc(x) (x<<1)
	#define rc(x) (x<<1|1)
	#define M(l,r) ((l+r)>>1)
	void pushup(int p)
	{
		tree[p]=tree[lc(p)]|tree[rc(p)];
	}
	void modify(int p,int l,int r,int x,int y)
	{
		if(l==r)
		{
			tree[p]=y;
			return ;
		}
		int mid=M(l,r);
		if(x<=mid) modify(lc(p),l,mid,x,y);
		else modify(rc(p),mid+1,r,x,y);
		pushup(p);
	}
	int query(int p,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R) return tree[p];
		int mid=M(l,r),res=0;
		if(L<=mid) res=query(lc(p),l,mid,L,R);
		if(mid<R) res|=query(rc(p),mid+1,r,L,R);
		return res;
	}
	void clear(int p,int l,int r)
	{
		tree[p]=0;
		if(l==r) return ;
		int mid=M(l,r);
		clear(lc(p),l,mid);
		clear(rc(p),mid+1,r);
	}
}T[31],G;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cin>>n>>q;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			G.modify(1,1,n,i,a[i]);
			for(int j=30;j>=0;j--)
			{
				if((1<<j)<=a[i])
				{
					f[i][j]=a[i]^(a[i]-(1<<j));
					T[j].modify(1,1,n,i,f[i][j]);
				}
				else f[i][j]=0;
				if((a[i]>>j)&1) lst[i][j]=j;
				else lst[i][j]=lst[i-1][j];
			}
		}
		while(q--)
		{
			int l,r,res=2,nor=0;
			cin>>l>>r;
			int Or=G.query(1,1,n,l,r),ans=(1ll<<(__lg(Or)+1))-1;
			if(Or==ans)
			{
				cout<<ans<<" "<<0<<"\n";
				continue ;
			}
			idx=0;
			for(int i=30;i>=0;i--)
			{
				if(!((Or>>i)&1)) continue ;
				if(lst[lst[r][i]-1][i]<l) continue ;
				for(int j=30;j>=0;j--)
				{
					T[j].modify(1,1,n,f[lst[r][i]][j],0);
				}
				lis[++idx]=lst[r][i];
			}
			for(int i=1;i<=idx;i++)
			{
				int por=0,sor=0;
				if(lis[i]>l) por=G.query(1,1,n,l,lis[i]-1);
				if(lis[i]<r) sor=G.query(1,1,n,lis[i]+1,r);
				for(int j=30;j>=0;j--)
				{
					if((f[lis[i]][j]|por|sor)==ans) res=1;
				}
			}
			for(int i=30;i>=0;i--)
			{
				if((T[i].query(1,1,n,l,r)|Or)==ans) res=1;
			}
			for(int i=1;i<=idx;i++)
			{
				for(int j=30;j>=0;j--)
				{
					T[i].modify(1,1,n,lis[i],f[lis[i]][j]);
				}
			}
			cout<<ans<<" "<<res<<"\n";
		}
		for(int i=30;i>=0;i--) T[i].clear(1,1,n);
		G.clear(1,1,n);
	}
}

詳細信息

Test #1:

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

input:

1
3 2
10 10 5
1 2
1 3

output:

15 2
15 0

result:

ok 4 number(s): "15 2 15 0"

Test #2:

score: 0
Accepted
time: 116ms
memory: 54872kb

input:

100000
1 1
924704060
1 1
1 1
149840457
1 1
1 1
515267304
1 1
1 1
635378394
1 1
1 1
416239424
1 1
1 1
960156404
1 1
1 1
431278082
1 1
1 1
629009153
1 1
1 1
140374311
1 1
1 1
245014761
1 1
1 1
445512399
1 1
1 1
43894730
1 1
1 1
129731646
1 1
1 1
711065534
1 1
1 1
322643984
1 1
1 1
482420443
1 1
1 1
20...

output:

1073741823 2
268435455 2
536870911 2
1073741823 2
536870911 2
1073741823 2
536870911 2
1073741823 2
268435455 2
268435455 2
536870911 2
67108863 2
134217727 2
1073741823 2
536870911 2
536870911 2
268435455 2
536870911 2
536870911 2
536870911 2
268435455 2
268435455 2
1073741823 2
16777215 2
10737418...

result:

ok 200000 numbers

Test #3:

score: -100
Wrong Answer
time: 130ms
memory: 52860kb

input:

50000
2 2
924896435 917026400
1 2
1 2
2 2
322948517 499114106
1 2
2 2
2 2
152908571 242548777
1 1
1 2
2 2
636974385 763173214
1 2
1 1
2 2
164965132 862298613
1 1
1 2
2 2
315078033 401694789
1 2
1 2
2 2
961358343 969300127
2 2
1 2
2 2
500628228 28065329
1 2
1 2
2 2
862229381 863649944
1 2
2 2
2 2
541...

output:

1073741823 2
1073741823 2
536870911 2
536870911 2
268435455 2
268435455 2
1073741823 2
1073741823 2
268435455 2
1073741823 2
536870911 2
536870911 2
1073741823 2
1073741823 2
536870911 2
536870911 2
1073741823 2
1073741823 2
1073741823 2
268435455 2
536870911 2
536870911 2
1073741823 2
1073741823 2
...

result:

wrong answer 1556th numbers differ - expected: '2', found: '1'