QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#128082 | #6631. Maximum Bitwise OR | KaphI | WA | 49ms | 7724kb | C++14 | 2.0kb | 2023-07-20 15:41:12 | 2023-07-20 15:41:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int T,n,m,a[N],L[N][32],v[N],q[N],ql,iq[N];
struct Tr{
int cnt[32],pos[32],lmin[32];
}tr[N<<2],rs;
Tr Merge(Tr &a,Tr &b){
Tr x;
for(int i=0;i<30;++i){
x.cnt[i]=a.cnt[i]+b.cnt[i];
if(x.cnt[i]==1)v[x.pos[i]=a.pos[i]|b.pos[i]]=1;
else x.pos[i]=0;
x.lmin[i]=min(a.lmin[i],b.lmin[i]);
if(a.pos[i]&&!iq[a.pos[i]])iq[a.pos[i]]=1,q[++ql]=a.pos[i];
if(b.pos[i]&&!iq[b.pos[i]])iq[b.pos[i]]=1,q[++ql]=b.pos[i];
}
for(int i=1;i<=ql;++i){
int u=q[i];
iq[u]=0;
if(!v[u]){
for(int j=0;j<30;++j)x.lmin[i]=min(x.lmin[i],L[u][i]);
}
}
ql=0;
for(int i=0;i<30;++i)v[x.pos[i]]=0;
return x;
}
void Js(int z,int y,int c){
if(z==y){
for(int i=0;i<30;++i){
if((a[z]>>i)&1){
tr[c].cnt[i]=1;
tr[c].pos[i]=z;
}
tr[c].lmin[i]=32;
}
return;
}
int mid=(z+y)>>1;
Js(z,mid,c<<1),Js(mid+1,y,c<<1|1);
tr[c]=Merge(tr[c<<1],tr[c<<1|1]);
}
void Qry(int z,int y,int c,int l,int r){
if(z>r)return;
if(l<=z&&y<=r){
if(z==l)rs=tr[c];
else rs=Merge(rs,tr[c]);
return;
}
int mid=(z+y)>>1;
if(l<=mid)Qry(z,mid,c<<1,l,r);
else Qry(mid+1,y,c<<1|1,l,r);
}
int getAns(){
int l=-1,r=-1,fl=0;
for(int i=29;~i;--i){
if(!rs.cnt[i]){
if(fl)l=i,r=(r==-1)? i:r;
}else fl=1;
}
// printf("__%d %d\n",l,r);
if(l==-1)return 0;
for(int i=r;i<30;++i)if(rs.lmin[i]<=l)return 1;
for(int i=0;i<30;++i)if(rs.pos[i]){
v[rs.pos[i]]++;
}
int w=2;
for(int i=r;i<30;++i){
int x=rs.pos[i];
if(!x||v[x]>1)continue;
if(L[x][i]<=l)w=1;
}
for(int i=0;i<30;++i)v[rs.pos[i]]=0;
return w;
}
void slv(){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
for(int j=0,k=0;a[i]>>j;++j){
L[i][j]=k;
if((a[i]>>j)&1)k=j+1;
}
}
Js(1,n,1);
while(m--){
int l,r;
scanf("%d %d",&l,&r);
Qry(1,n,1,l,r);
for(int i=29;~i;i--)if(rs.cnt[i]){
printf("%d %d\n",(1<<(i+1))-1,getAns());
break;
}
}
}
int main(){
scanf("%d",&T);
while(T--)slv();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7724kb
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: 49ms
memory: 7684kb
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'