QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#147560#6631. Maximum Bitwise ORqzezWA 34ms3848kbC++141.8kb2023-08-23 13:39:032023-08-25 01:39:43

Judging History

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

  • [2023-08-25 01:39:43]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:3848kb
  • [2023-08-23 13:39:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
	if(x.empty())return out<<"[]";
	out<<'['<<x[0];
	for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
	return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
	cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
	cerr<<x<<' ',debug(y...);
}
const int N=1e5+10,M=30;
int T,n,m,a[N];
struct node{
	int sum,mx[M];
	node operator += (const node &a){
		sum|=a.sum;
		for(int i=0;i<M;i++)mx[i]=max(mx[i],a.mx[i]);
		return *this;
	}
	node operator + (const node &a)const{
		return node(*this)+=a;
	}
}t[N<<2];
void pushup(int rt){
	t[rt]=t[rt<<1]+t[rt<<1|1];
}
void build(int l=1,int r=n,int rt=1){
	if(l==r){
		t[rt].sum=a[l];
		for(int i=0;i<M;i++){
			if((1<<i)<=a[l])t[rt].mx[i]=(a[l]-(1<<i))^a[l];
			else t[rt].mx[i]=0;
		}
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,rt<<1);
	build(mid+1,r,rt<<1|1);
	pushup(rt);
}
node query(int L,int R,int l=1,int r=n,int rt=1){
	if(L<=l&&r<=R)return t[rt];
	int mid=(l+r)>>1;
	if(R<=mid)return query(L,R,l,mid,rt<<1);
	if(mid<L)return query(L,R,mid+1,r,rt<<1|1);
	return query(L,R,l,mid,rt<<1)+query(L,R,mid+1,r,rt<<1|1);
}
void get(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	node tmp;
	build();
	for(int l,r;m--;){
		scanf("%d%d",&l,&r);
		tmp=query(l,r);
		int x=tmp.sum;
		printf("%d ",(1<<__lg(x)+1)-1);
		auto chk=[&]{
			for(int i=0;i<M;i++){
				int sum=tmp.sum|tmp.mx[i];
				if(!(sum&(sum+1)))return 1;
			}
			return 0;
		};
		if(!(x&(x+1)))puts("0");
		else if(chk())puts("1");
		else puts("2");
	}
}
int main(){
	for(scanf("%d",&T);T--;)get();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3848kb

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: 34ms
memory: 3784kb

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: 21ms
memory: 3796kb

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'