QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#485250 | #6631. Maximum Bitwise OR | ucup-team1525# | WA | 182ms | 6624kb | C++20 | 1.9kb | 2024-07-20 15:24:23 | 2024-07-20 15:24:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
int n,q;
int a[N+5];
struct Que{
int l,r,a,b;
}qu[N+5];
struct Ans{
int val,c;
Ans(int val=0,int c=0):val(val),c(c){}
}ans[N+5];
bool check(int x){
while(x){
if(!(x&1)) return 0;
x>>=1;
}
return 1;
}
pair<int,int> get(int x){
int a=-1,b=-1;
for(int i=0;x>>i;i++)
if(!(x>>i&1)){
if(a==-1) a=i;
b=i;
}
return make_pair(a,b);
}
void work1(){
static int s[N+5];
fill(ans,ans+q+1,Ans());
for(int i=0;i<30;i++){
for(int j=1;j<=n;j++)
s[j]=s[j-1]+(a[j]>>i&1);
for(int j=1;j<=q;j++){
auto [l,r,a,b]=qu[j];
if(s[r]-s[l-1]>0) ans[j].val|=1<<i;
}
}
for(int i=1;i<=q;i++){
if(check(ans[i].val)){
ans[i].c=0; qu[i].a=qu[i].b=-1;
}
else{
ans[i].c=2;
auto [aa,bb]=get(ans[i].val);
qu[i].a=aa; qu[i].b=bb;
int x=__lg(ans[i].val);
ans[i].val|=(1<<x)-1;
}
}
}
int chk(int x,int l,int r){
int a=x>>r+1,b=x&((1<<l)-1);
return a>0&&((a<<r+1)|b)==x;
}
void work2(){
static int s[N+5];
for(int aa=0;aa<30;aa++)
for(int bb=aa;bb<30;bb++){
for(int i=1;i<=n;i++)
s[i]=s[i-1]+chk(a[i],aa,bb);
for(int i=1;i<=q;i++){
auto [l,r,a,b]=qu[i];
if(a==aa&&b==bb&&s[r]-s[l-1]>0)
ans[i].c=1;
}
}
}
void solve(){
scanf("%d %d",&n,&q);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=q;i++)
scanf("%d %d",&qu[i].l,&qu[i].r);
work1();
work2();
for(int i=1;i<=q;i++)
printf("%d %d\n",ans[i].val,ans[i].c);
}
int main(){
int t; scanf("%d",&t);
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6624kb
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: 182ms
memory: 4704kb
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: -100
Wrong Answer
time: 163ms
memory: 5996kb
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:
wrong answer 1556th numbers differ - expected: '2', found: '1'