QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#128090#6631. Maximum Bitwise ORKaphIWA 96ms7720kbC++142.1kb2023-07-20 15:44:192023-07-20 15:44:22

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 15:44:22]
  • 评测
  • 测评结果:WA
  • 用时:96ms
  • 内存:7720kb
  • [2023-07-20 15:44:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int T,n,m,a[N],L[N][32],v[N],q[N],ql,iq[N];
struct Tr{
	int cnt[32],pos[32],lmin[32];
}tr[N<<2],rs;
Tr Merge(Tr &a,Tr &b){
	Tr x;
	for(int i=0;i<30;++i){
		x.cnt[i]=a.cnt[i]+b.cnt[i];
		if(x.cnt[i]==1)v[x.pos[i]=a.pos[i]|b.pos[i]]=1;
		else x.pos[i]=0;
		x.lmin[i]=min(a.lmin[i],b.lmin[i]);
		if(a.pos[i]&&!iq[a.pos[i]])iq[a.pos[i]]=1,q[++ql]=a.pos[i];
		if(b.pos[i]&&!iq[b.pos[i]])iq[b.pos[i]]=1,q[++ql]=b.pos[i];
	}
	for(int i=1;i<=ql;++i){
		int u=q[i];
		iq[u]=0;
		if(!v[u]){
			for(int j=0;j<30;++j)x.lmin[i]=min(x.lmin[i],L[u][i]);
		}
	}
	ql=0;
	for(int i=0;i<30;++i)v[x.pos[i]]=0;
	return x;
}
void Js(int z,int y,int c){
	if(z==y){
		for(int i=0;i<30;++i){
			if((a[z]>>i)&1){
				tr[c].cnt[i]=1;
				tr[c].pos[i]=z;
			}else {
				tr[c].cnt[i]=0;
				tr[c].pos[i]=0;
			}
			tr[c].lmin[i]=32;
		}
		return;
	}
	int mid=(z+y)>>1;
	Js(z,mid,c<<1),Js(mid+1,y,c<<1|1);
	tr[c]=Merge(tr[c<<1],tr[c<<1|1]);
}
void Qry(int z,int y,int c,int l,int r){
	if(z>r)return;
	if(l<=z&&y<=r){
		if(z==l)rs=tr[c];
		else rs=Merge(rs,tr[c]);
		return;
	}
	int mid=(z+y)>>1;
	if(l<=mid)Qry(z,mid,c<<1,l,r);
	else Qry(mid+1,y,c<<1|1,l,r);
}
int getAns(){
	int l=-1,r=-1,fl=0;
	for(int i=29;~i;--i){
		if(!rs.cnt[i]){
			if(fl)l=i,r=(r==-1)? i:r;
		}else fl=1;
	}
//	printf("__%d %d\n",l,r);
	if(l==-1)return 0;
	for(int i=r;i<30;++i)if(rs.lmin[i]<=l)return 1;
	for(int i=0;i<30;++i)if(rs.pos[i]){
		v[rs.pos[i]]++;
	}
	int w=2;
	for(int i=r;i<30;++i){
		int x=rs.pos[i];
		if(!x||v[x]>1)continue;
		if(L[x][i]<=l)w=1;
	}
	for(int i=0;i<30;++i)v[rs.pos[i]]=0;
	return w;
}
void slv(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		for(int j=0,k=0;a[i]>>j;++j){
			L[i][j]=k;
			if((a[i]>>j)&1)k=j+1;
		}
	}
	Js(1,n,1);
	while(m--){
		int l,r;
		scanf("%d %d",&l,&r);
		Qry(1,n,1,l,r);
		for(int i=29;~i;i--)if(rs.cnt[i]){
			printf("%d %d\n",(1<<(i+1))-1,getAns());
			break;
		}
	}
}
int main(){
	scanf("%d",&T);
	while(T--)slv();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 80ms
memory: 5632kb

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: 0
Accepted
time: 91ms
memory: 5672kb

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:

ok 200000 numbers

Test #4:

score: -100
Wrong Answer
time: 96ms
memory: 5648kb

input:

33333
3 3
925088809 339284112 289540728
3 3
1 3
1 1
3 3
422399522 892365243 216341776
3 3
3 3
1 2
3 3
668932010 837523227 840095874
1 3
1 3
3 3
3 3
731584574 357877180 359063739
1 1
1 1
3 3
3 3
463358343 833924976 847087403
2 3
3 3
1 2
3 3
377154649 772000701 656357011
2 3
1 2
2 3
3 3
977492169 5540...

output:

536870911 2
1073741823 2
1073741823 2
268435455 2
268435455 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
536870911 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
67108863 2
1073741823 2
1073741...

result:

wrong answer 67th numbers differ - expected: '536870911', found: '33554431'