QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#148744#6631. Maximum Bitwise OR275307894aWA 44ms97708kbC++142.5kb2023-08-23 18:24:072023-08-23 20:26:57

Judging History

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

  • [2023-08-23 20:26:57]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:97708kb
  • [2023-08-23 18:24:07]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e5+5,M=N*4+5,K=14348907+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,m,k,A[N];
struct Node{
	int f[30],g[30];
	Node(){Me(g,0x3f);Me(f,0);}
	void add1(int x){
		for(int i=0;i<30;i++) if(A[x]>>i&1) f[i]=x;
	}
	void add2(int x){
		for(int i=0;i<30;i++) if(f[i]==x) return ;x=A[x];
		int LA=-1;for(int i=0;i<30;i++) if(x>>i&1) g[i]=min(g[i],LA+1),LA=i;
	}
	Node operator +(const Node &B)const{
		Node C;
		for(int i=0;i<30;i++) C.g[i]=min(g[i],B.g[i]);
		for(int i=0;i<30;i++) {
			if(f[i]==-1||B.f[i]==-1||(f[i]&&B.f[i])) C.f[i]=-1;
			else C.f[i]=f[i]+B.f[i];
		}
		for(int i=0;i<30;i++) {
			if(f[i]>0&&f[i]^C.f[i]) C.add2(f[i]);
			if(B.f[i]>0&&B.f[i]^C.f[i]) C.add2(B.f[i]);
		}
		return C;
	}
};
namespace Tree{
	#define ls v<<1
	#define rs v<<1|1
	Node f[M];
	void Up(int v){f[v]=f[ls]+f[rs];}
	void BD(int l=1,int r=n,int v=1){
		if(l==r) return f[v].add1(l);int m=l+r>>1;
		BD(l,m,ls);BD(m+1,r,rs);Up(v);
	}
	Node qry(int x,int y,int l=1,int r=n,int v=1){
		if(x<=l&&r<=y) return f[v];int m=l+r>>1;
		if(y<=m) return qry(x,y,l,m,ls);if(x>m) return qry(x,y,m+1,r,rs);
		return qry(x,y,l,m,ls)+qry(x,y,m+1,r,rs);
	}
}
void Solve(){
	int i,j;scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++) scanf("%d",&A[i]);
	Tree::BD();
	while(m--){
		int x,y;scanf("%d%d",&x,&y);
		Node p=Tree::qry(x,y);
		int tar=-1;
		for(i=29;~i;i--) if(p.f[i]){tar=i;break;}
		int flag=0;for(i=0;i<=tar;i++) if(!p.f[i]) flag=1;
		printf("%d ",(1<<tar+1)-1);
		if(!flag) {puts("0");continue;}
		for(i=0;i<30;i++) if(p.f[i]>0){
			int x=A[p.f[i]];
			int flag=0;for(j=0;j<30;j++) if(p.f[j]==p.f[i]) flag++;
			if(flag>1) continue;
			int LA=-1;for(j=0;j<i;j++) if(x>>j&1) LA=j;
			p.g[i]=min(p.g[i],LA+1);
		}
		flag=0;int l=0,r=tar;
		while(p.f[l]) l++;while(p.f[r]) r--;
		for(i=0;i<30;i++) if(p.g[i]<=l&&r<=i) flag=1;
		if(flag) puts("1");
		else puts("2");
	}
}
int main(){
	int t;
	scanf("%d",&t);
	// t=1;
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 44ms
memory: 97564kb

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
1073741823 2
1073741823 2
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1073741823 0
1...

result:

wrong answer 3rd numbers differ - expected: '268435455', found: '1073741823'