QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181905#6631. Maximum Bitwise ORucup-team134WA 88ms56516kbC++142.5kb2023-09-17 03:39:422023-09-17 03:39:42

Judging History

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

  • [2023-09-17 03:39:42]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:56516kb
  • [2023-09-17 03:39:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back

const int N=100050;
const int LOG=30;
int a[N],last[N][LOG];
int cnt[N];
int b[N];

const int M=2*LOG*N;
int root[LOG],ls[M],rs[M],mx[M],tsz;
int bld[N][LOG];
void Build(int&c,int ss,int se,int lg){
	c=++tsz;
	if(ss==se){
		mx[c]=bld[ss][lg];
		return;
	}
	int mid=ss+se>>1;
	Build(ls[c],ss,mid,lg);
	Build(rs[c],mid+1,se,lg);
	mx[c]=max(mx[ls[c]],mx[rs[c]]);
}
int Get(int c,int ss,int se,int qs,int qe){
	if(qs>qe||qs>se||ss>qe)return -1;
	if(qs<=ss&&qe>=se)return mx[c];
	int mid=ss+se>>1;
	return max(Get(ls[c],ss,mid,qs,qe),Get(rs[c],mid+1,se,qs,qe));
}

int main(){
	int t;
	scanf("%i",&t);
	while(t--){
		int n,q;
		scanf("%i %i",&n,&q);
		for(int i=1;i<=n;i++){
			scanf("%i",&a[i]);
			for(int j=0;j<LOG;j++){
				if(a[i]>>j&1){
					last[i][j]=i;
				}else{
					last[i][j]=last[i-1][j];
				}
			}
			int one=-1;
			for(int j=LOG-1;j>=0;j--){
				if(a[i]>>j&1){
					one=j;
				}
				if(one!=-1){
					bld[i][j]=one;
				}else{
					bld[i][j]=-1;
				}
			}
		}
		for(int i=0;i<LOG;i++){
			Build(root[i],1,n,i);
		}
		while(q--){
			int l,r;
			scanf("%i %i",&l,&r);
			int OR=0,mx=0;
			for(int i=0;i<LOG;i++){
				if(last[r][i]>=l){
					OR|=(1<<i);
					mx=(1<<(i+1))-1;
				}
			}
			int ans=0;
			if(OR!=mx){
				ans=2;
				int L=0;
				while(last[r][L]>=l)L++;
				int R=LOG-1;
				while(last[r][R]<l)R--;
				while(last[r][R]>=l)R--;
				//printf("L:%i R:%i\n",L,R);

				vector<int> clr;
				for(int i=0;i<LOG;i++){
					if(last[r][i]>=l){
						int spec=last[r][i];
						if(last[spec][i]>=l)continue;
						cnt[spec]++;
						b[spec]=i;
						clr.pb(spec);
						//printf("i:%i spec:%i\n",i,spec);
					}
				}
				sort(clr.begin(),clr.end());
				int pre=l;
				int mxr=-1;
				for(int x:clr){
					if(cnt[x]==1){
						/*bool ok=true;
						for(int i=L;i<R;i++){
							if(a[x]>>i&1){
								ok=false;
								break;
							}
						}
						bool good=false;
						for(int i=R;i<LOG;i++){
							if(a[x]>>i&1){
								if(i==b[x]){
									good=true;
								}
								break;
							}
						}
						if(!good)ok=false;
						if(ok)ans=1;*/
						if(bld[x][L]>=R && bld[x][L]==b[x]){
							ans=1;
						}
					}
					mxr=max(mxr,Get(root[L],1,n,pre,x-1));
					pre=x+1;
					cnt[x]=0;
				}
				mxr=max(mxr,Get(root[L],1,n,pre,r));
				//printf("mxr:%i\n",mxr);
				if(mxr>=R)ans=1;
			}
			printf("%i %i\n",mx,ans);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 78ms
memory: 15396kb

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: 88ms
memory: 56516kb

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'