QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#190432#6631. Maximum Bitwise ORqzhwlzyWA 170ms116504kbC++142.3kb2023-09-28 21:13:142023-09-28 21:13:14

Judging History

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

  • [2023-09-28 21:13:14]
  • 评测
  • 测评结果:WA
  • 用时:170ms
  • 内存:116504kb
  • [2023-09-28 21:13:14]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define maxn 100005
#define maxm 35
using namespace std;
int T,n,q,in[maxn],l,r,val[maxn]; bool uni[maxn]; int calc(int val,int bit){return val^(val-(1<<bit));}
struct node{
	int spe[maxm],mmax[maxm],l,r; node(){memset(spe,0,sizeof(spe)); memset(mmax,0,sizeof(mmax));}
	node operator += (const node &x){
		for(int i=0;i<maxm;i++) mmax[i]=max(mmax[i],x.mmax[i]);
		vector<int> del; for(int i=0;i<maxm;i++) if(!spe[i]||!x.spe[i])
			{if(spe[i]>0) uni[spe[i]]=1,del.push_back(spe[i]); if(x.spe[i]>0) uni[x.spe[i]]=1,del.push_back(x.spe[i]);}
		for(int i=0;i<maxm;i++) if(spe[i]&&x.spe[i]){
			if(spe[i]>0&&!uni[spe[i]]) for(int j=0;j<maxm&&(1<<j)<=in[spe[i]];j++) mmax[i]=max(mmax[i],calc(in[spe[i]],j));
			if(x.spe[i]>0&&!uni[x.spe[i]])
				{for(int j=0;j<maxm&&(1<<j)<=in[x.spe[i]];j++) mmax[i]=max(mmax[i],calc(in[x.spe[i]],j));} spe[i]=-1;
		}else spe[i]|=x.spe[i]; for(auto i:del) uni[i]=0; return *this;
	}
	node operator + (const node &a)const{
		return node(*this)+=a;
	}
}a[maxn*4];
void pushup(int p){a[p]=a[p<<1]+a[p<<1|1];}
void build(int p,int l,int r){
	a[p].l=l; a[p].r=r; if(l==r)
		{for(int i=0;i<maxm;i++) a[p].mmax[i]=0,a[p].spe[i]=(in[l]&(1<<i))?l:0; return;}
	build(p<<1,l,(l+r)>>1); build(p<<1|1,((l+r)>>1)+1,r); pushup(p); a[p].l=l; a[p].r=r;
}
node query(int p,int l,int r){
	if(l<=a[p].l&&r>=a[p].r) return a[p]; node res;
	if(r<=a[p<<1].r) return query(p<<1,l,r); if(l>=a[p<<1|1].l) return query(p<<1|1,l,r);
	return query(p<<1,l,r)+query(p<<1|1,l,r);
}
int main(){
	scanf("%d",&T); while(T--){
		scanf("%d%d",&n,&q); for(int i=1;i<=n;i++) scanf("%d",&in[i]),uni[i]=0;
		build(1,1,n); while(q--){
			scanf("%d%d",&l,&r); node x=query(1,l,r); int now=0;
			for(int i=0;i<maxm;i++) now|=(x.spe[i]!=0)*(1<<i); int ans=1;
			for(;ans<=now;ans*=2); ans--; printf("%d ",ans); if(now==ans){printf("0\n"); continue;}
			bool flag=0; for(int i=0;i<maxm;i++) if((now|x.mmax[i])==ans){printf("1\n"); flag=1; break;}
			for(int i=0;i<maxm;i++) if(x.spe[i]>0) val[x.spe[i]]|=(1<<i);
			for(int i=0;i<maxm&&!flag;i++) if(val[x.spe[i]]){
				int res=now^val[x.spe[i]]; for(int j=0;j<maxm&&(1<<j)<=in[x.spe[i]];j++)
					if((res|calc(in[x.spe[i]],j))==ans){printf("1\n"); flag=1; break;} val[i]=0;
			} if(!flag) printf("2\n");
		}
	} return 0;
}

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 116200kb

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: 89ms
memory: 116208kb

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: 129ms
memory: 116236kb

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: 170ms
memory: 116504kb

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