QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227809 | #6631. Maximum Bitwise OR | ugly2333 | WA | 100ms | 12328kb | C++20 | 1.8kb | 2023-10-28 00:00:48 | 2023-10-28 00:00:48 |
Judging History
answer
//Δ_A
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 100005;
const int M = 33;
const int W = 465;
int n,q,m=30,a[N],b[M][M],c[M],f[N][M],e[N][M],p[M][M],g[N][W];
vector<int> v,h[N];
int main(){
int T,i,j,k,o,l,r,t,s,u,z;
scanf("%d",&T);
o=0;
for(i=0;i<m;i++)
for(j=i;j<m;j++)
p[i][j]=o++;
while(T--){
scanf("%d%d",&n,&q);
for(i=1;i<=n;i++)
scanf("%d",a+i);
for(i=1;i<=n;i++)
for(j=0;j<m;j++)
f[i][j]=(a[i]>>j)&1,e[i][j]=f[i][j]*i;
for(i=1;i<=n;i++)
for(j=0;j<m;j++)
f[i][j]+=f[i-1][j],e[i][j]+=e[i-1][j];
for(i=1;i<=n;i++){
memset(b,0,sizeof(b));
o=m;
for(j=m-1;j>=0;j--){
if((a[i]>>j)&1)
o=j;
if(o<m){
for(k=j;k<=o;k++)
b[j][k]=1;
}
}
o=0;
for(j=0;j<m;j++)
for(k=j;k<m;k++)
g[i][o++]=b[j][k];
}
for(i=1;i<=n;i++)
for(j=0;j<W;j++)
g[i][j]+=g[i-1][j];
while(q--){
scanf("%d%d",&l,&r);
l--;
for(i=0;i<m;i++)
c[i]=f[r][i]-f[l][i];
o=m-1;
while(o>=0&&!c[o])o--;
if(o<0){
printf("0 0\n");
continue;
}
printf("%d ",(2<<o)-1);
v.clear();
j=m,k=-1;
for(i=0;i<=o;i++){
if(c[i]==1){
t=e[r][i]-e[l][i];
v.push_back(t);
h[t].push_back(i);
}
if(c[i]==0)
j=min(j,i),k=max(k,i);
}
if(j>k)
printf("0\n");
else{
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
u=p[j][k];
s=g[r][u]-g[l][u];
for(i=0;i<v.size();i++){
t=v[i];
s-=g[t][u]-g[t-1][u];
sort(h[t].begin(),h[t].end());
z=p[min(h[t][0],j)][max(h[t].back(),k)];
s+=g[t][z]-g[t-1][z];
h[t].clear();
}
if(s)
printf("1\n");
else
printf("2\n");
}
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 12328kb
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: 95ms
memory: 11712kb
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: 97ms
memory: 12224kb
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: 0
Accepted
time: 100ms
memory: 10516kb
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:
ok 199998 numbers
Test #5:
score: -100
Wrong Answer
time: 99ms
memory: 11740kb
input:
20000 5 5 925473558 183799537 561353092 858424993 765513347 2 4 1 1 1 2 3 5 1 4 5 5 141075166 375934371 754066286 663820319 906342255 3 5 1 1 4 5 1 4 2 3 5 5 417114008 270241961 121113861 381529080 772448388 1 3 1 1 2 5 5 5 2 2 5 5 668136057 138968211 856562545 187058570 699131353 4 5 3 4 5 5 2 4 3 ...
output:
1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 268435455 2 1073741823 2 1073741823 2 1073741823 2 536870911 2 536870911 2 1073741823 2 1073741823 2 536870911 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 1073741823 2 268435455 2 107374...
result:
wrong answer 11764th numbers differ - expected: '1', found: '2'