QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#147996#6631. Maximum Bitwise ORqzezWA 8ms97408kbC++143.0kb2023-08-23 14:52:322023-08-23 20:15:23

Judging History

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

  • [2023-08-23 20:15:23]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:97408kb
  • [2023-08-23 14:52:32]
  • 提交

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];
void ins(int *mx,int id){
	for(int i=0;i<M;i++){
		if((1<<i)<=a[id]){
			mx[i]=max(mx[i],a[id]^(a[id]-(1<<i)));
		}
	}
}
int is[N];
struct node{
	int id[M],mx[M];
	node(){
		memset(id,0,sizeof id);
		memset(mx,0,sizeof mx);
	}
	node operator += (const node &a){
		for(int i=0;i<M;i++){
			mx[i]=max(mx[i],a.mx[i]);
		}
		for(int i=0;i<M;i++){
			if(!id[i]||!a.id[i]){
				if(id[i]>0)is[id[i]]=0;
				if(a.id[i]>0)is[a.id[i]]=0;
			}
		}
		for(int i=0;i<M;i++){
			if(id[i]&&a.id[i]){
				if(id[i]>0&&is[id[i]])ins(mx,id[i]);
				if(a.id[i]>0&&is[a.id[i]])ins(mx,a.id[i]);
				id[i]=-1;
			}else{
				id[i]|=a.id[i];
			}
		}
		for(int i=0;i<M;i++){
			if(!id[i]||!a.id[i]){
				if(id[i]>0)is[id[i]]=1;
				if(a.id[i]>0)is[a.id[i]]=1;
			}
		}
		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){
		for(int i=0;i<M;i++){
			t[rt].mx[i]=0;
			t[rt].id[i]=a[l]>>i&1?l: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);
}
int val[N];
int TT;
void get(){
	scanf("%d%d",&n,&m);
	fill(is+1,is+1+n,1);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	build();
	for(int l,r;m--;){
		scanf("%d%d",&l,&r);
		if(++TT==5770){
			cout<<n<<endl<<ary(a,1,n)<<endl<<l<<' '<<r<<endl;
		}
		node x=query(l,r);
		int sum=0;
		for(int i=0;i<M;i++){
			if(x.id[i])sum|=1<<i;
		}
		int goal=(1<<__lg(sum)+1)-1;
		auto chk1=[&](){
			for(int i=0;i<M;i++){
				if((sum|x.mx[i])==goal)return 1;
			}
			for(int i=0;i<M;i++){
				if(x.id[i]>0)val[x.id[i]]|=1<<i;
			}
			int flag=0;
			for(int i=0;i<M;i++){
				int id=x.id[i];
				if(id<=0)continue;
				if(val[id]){
					int now=sum^val[id];
					for(int j=0;j<M;j++){
						if((1<<j)<=a[id]){
							if((now|(a[id]^(a[id]-(1<<j))))==goal)flag=1;
						}
					}
					val[id]=0;
				}
			}
			return flag;
		};
		if(n==3)continue;
		if(sum==goal)printf("%d 0\n",goal);
		else if(chk1())printf("%d 1\n",goal);
		else printf("%d 2\n",goal);
	}
}
int main(){
	scanf("%d",&T);
	for(;T--;)get();
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 97408kb

input:

1
3 2
10 10 5
1 2
1 3

output:


result:

wrong answer Answer contains longer sequence [length = 4], but output contains 0 elements