QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#376555 | #6631. Maximum Bitwise OR | zhouqixuan | WA | 54ms | 69660kb | C++14 | 2.6kb | 2024-04-04 11:48:30 | 2024-04-04 11:48:30 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
typedef pair<int,int>PII;
const int N=1e5+5;
int n,m;
int a[N];
struct node{int w[30],o;vector<PII>v;};
struct Node{
int l,r,maxn;
node x;
}tr[N*4];
node merge(node a,node b){
node c;
c.o=a.o|b.o;
for(int i=0;i<30;i++) c.w[i]=max(a.w[i],b.w[i]);
for(PII t:a.v){
int x=t.first,y=t.second;
if((y|b.o)!=c.o) c.v.push_back({x,y|b.o});
else for(int i=0;i<__lg(x);i++) c.w[i]=max(c.w[i],x^(x-(1<<i)));
}
for(PII t:a.v){
int x=t.first,y=t.second;
if((y|a.o)!=c.o) c.v.push_back({x,y|a.o});
else for(int i=0;i<=__lg(x);i++) c.w[i]=max(c.w[i],x^(x-(1<<i)));
}
return c;
}
void pushup(int u){
tr[u].maxn=max(tr[u<<1].maxn,tr[u<<1|1].maxn);
tr[u].x=merge(tr[u<<1].x,tr[u<<1|1].x);
return;
}
void build(int u,int l,int r){
tr[u]={l,r};
if(l==r){
tr[u].maxn=a[l];
tr[u].x.o=a[l],tr[u].x.v.clear();
if(a[l]) tr[u].x.v.push_back(make_pair(a[l],0));
memset(tr[u].x.w,0,sizeof(tr[u].x.w));
return;
}
int mid=(l+r)>>1;
build(u<<1,l,mid);
build(u<<1|1,mid+1,r);
pushup(u);
return;
}
int query_max(int u,int l,int r){
if(l<=tr[u].l && tr[u].r<=r) return tr[u].maxn;
int mid=(tr[u].l+tr[u].r)>>1,res=0;
if(l<=mid) res=max(res,query_max(u<<1,l,r));
if(mid<r) res=max(res,query_max(u<<1|1,l,r));
return res;
}
node query(int u,int l,int r){
if(l<=tr[u].l && tr[u].r<=r) return tr[u].x;
int mid=(tr[u].l+tr[u].r)>>1;
if(r<=mid) return query(u<<1,l,r);
if(l>mid) return query(u<<1|1,l,r);
return merge(query(u<<1,l,r),query(u<<1|1,l,r));
}
void calc(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
build(1,1,n);
while(m--){
int l,r;
scanf("%d%d",&l,&r);
int ans=(1<<__lg(query_max(1,l,r))+1)-1;
printf("%d ",ans);
node t=query(1,l,r);
if(t.o==ans) puts("0");
else{
int flag=0;
for(int i=0;i<30;i++) if((t.w[i]|t.o)==ans){flag=1;break;}
for(PII tt:t.v){
int x=tt.first,y=tt.second;
for(int i=0;i<=__lg(x);i++)
if((y|x^x-(1<<i))==ans){
flag=1;
break;
}
}
if(flag) puts("1");
else puts("2");
}
}
return;
}
int main(){
int T;
scanf("%d",&T);
while(T--) calc();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 69368kb
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: 36ms
memory: 69660kb
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: 52ms
memory: 69428kb
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: 54ms
memory: 69372kb
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 8528th numbers differ - expected: '2', found: '1'