QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#391860#6631. Maximum Bitwise ORNahidameowWA 99ms5976kbC++203.3kb2024-04-16 21:18:022024-04-16 21:18:04

Judging History

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

  • [2024-04-16 21:18:04]
  • 评测
  • 测评结果:WA
  • 用时:99ms
  • 内存:5976kb
  • [2024-04-16 21:18:02]
  • 提交

answer

#include<bits/stdc++.h>
#define pd push_back
#define all(A) A.begin(),A.end()
#define lower_bound lb
#define ve std::vector
typedef long long ll;
typedef long long ll;
typedef __int128 Int;
typedef unsigned long long ul;
typedef long double LD;
bool FileIfstream(std::string name){
	std::ifstream f(name.c_str());
	return f.good();
}
namespace Math{
	ll QP(ll x,ll y,ll mod){ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1)ans=ans*x%mod;return ans;}
	ll inv(ll x,ll mod){return QP(x,mod-2,mod);}
}
const int N=2e5+10;
const int mod=998244353;
struct Spare_Table{
	int st[N][25];
	int LOG2[N],n;
	void make(int _n,ve<int>&v){
		n=_n;
		for(int i=1;i<=n;i++)
			st[i][0]=v[i];
		for(int i=2;i<=n;i++)
			LOG2[i]=LOG2[i>>1]+1;
		for(int j=1;j<=20;j++)
			for(int i=1;i+(1<<j)-1<=n;i++)
				st[i][j]=(st[i][j-1]|st[i+(1<<j-1)][j-1]);
	}
	int query(int l,int r){
		assert(l<=r);
		int k=LOG2[r-l+1];
		return st[l][k]|st[r-(1<<k)+1][k];
	}
}ST;
struct node{
	std::array<int,2> S[32];
	int dS[32];
};
node operator + (node L,node R){
	node ans;
	for(int i=0;i<=30;i++)
		ans.dS[i]=std::max(L.dS[i],R.dS[i]);
	for(int i=0;i<=30;i++)
		ans.S[i][0]=L.S[i][0]+R.S[i][0];
	for(int i=0;i<=30;i++)
		if(ans.S[i][0]!=1)ans.S[i][1]=-1;
		else ans.S[i][1]=std::max(L.S[i][1],R.S[i][1]);
	return ans;
}
struct sg_tree{
	node tr[N<<2];
	void pushup(int rt){
		tr[rt]=tr[rt<<1]+tr[rt<<1|1];}
	void build(int rt,int l,int r,ve<int>&v){
		if(l==r){
			for(int i=0;i<=30;i++)
				tr[rt].dS[i]=((v[l]<(1<<i))?0:(v[l]^(v[l]-(1<<i))));
			for(int i=0;i<=30;i++)
				tr[rt].S[i]={0,-1};
			for(int i=0;i<=30;i++)
				if(v[l]>>i&1)tr[rt].S[i][0]=1,tr[rt].S[i][1]=l; 
			return;
		}
		auto mid=l+r>>1;
		build(rt<<1,l,mid,v);build(rt<<1|1,mid+1,r,v); 
		pushup(rt);
	}
	node query(int rt,int l,int r,int x,int y){
		if(x<=l&&r<=y)return tr[rt];
		auto mid=l+r>>1;
		if(x<=mid&&y>mid)return query(rt<<1,l,mid,x,y)+query(rt<<1|1,mid+1,r,x,y);
		if(x<=mid)return query(rt<<1,l,mid,x,y);
		if(y>mid)return query(rt<<1|1,mid+1,r,x,y);
	}
}Tr;
void solve(){
	//don't forget to open long long
	int n,m;std::cin>>n>>m;
	ve<int>v(n+1);
	for(int i=1;i<=n;i++)std::cin>>v[i];
	ST.make(n,v);Tr.build(1,1,n,v);
	while(m--){
		int l,r;std::cin>>l>>r;
		int S=ST.query(l,r);
		if(!S){std::cout<<0<<' '<<0<<'\n';continue;}
		int T=(1<<std::__lg(S)+1)-1;
		if(S==T){std::cout<<T<<' '<<0<<'\n';continue;}
		auto check=[&]()->bool{
			auto Q=Tr.query(1,1,n,l,r);
			ve<int>pos;pos.pd(l-1),pos.pd(r+1);
			for(int i=0;i<=30;i++)
				if(Q.S[i][1]!=-1)pos.pd(Q.S[i][1]);
			sort(all(pos));pos.erase(unique(all(pos)),pos.end());
			ve<int>A(31,0);
			for(int i=0;i+1<pos.size();i++){
				int L=pos[i]+1,R=pos[i+1]-1;
				if(L<=R){
					auto K=Tr.query(1,1,n,L,R);
					for(int j=0;j<=30;j++)
						A[j]=std::max(A[j],K.dS[j]);
				}
			}
			for(int i=0;i<=30;i++)
				if((A[i]|S)==T)
					return true;
			
			return false;
		};
		std::cout<<T<<' '<<(check()?1:2)<<'\n';
	}
}
int main(){
#ifndef ONLINE_JUDGE
	if(!FileIfstream("IO.in")){
		freopen("IO.in","w",stdout);
		return 0;
	}
	freopen("IO.in","r",stdin);
	freopen("IO.out","w",stdout);
#endif
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	int T=1;
	std::cin>>T;
	while(T--)solve();

	return 0;
}




詳細信息

Test #1:

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

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: 5716kb

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: 97ms
memory: 5636kb

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: 99ms
memory: 5748kb

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 9322nd numbers differ - expected: '1', found: '2'