QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#463143#6631. Maximum Bitwise ORgrass8cow#WA 231ms5856kbC++171.8kb2024-07-04 14:24:182024-07-04 14:24:18

Judging History

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

  • [2024-07-04 14:24:18]
  • 评测
  • 测评结果:WA
  • 用时:231ms
  • 内存:5856kb
  • [2024-07-04 14:24:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,q,a[100100],l1[101000][30],l2[101000][30][30];
void sol(){
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int j=0;j<30;j++)l1[n+1][j]=n+1;
    for(int j=0;j<30;j++)for(int k=j;k<30;k++)l2[n+1][j][k]=n+1;
    for(int i=n;i;i--){
        for(int j=0;j<30;j++)if((a[i]>>j)&1)l1[i][j]=i;else l1[i][j]=l1[i+1][j];
        int t=-1;
        for(int j=0;j<30;j++)for(int k=j;k<30;k++)
            l2[i][j][k]=l2[i+1][j][k];
        for(int j=0;j<30;j++)if((a[i]>>j)&1){
            for(int x=t+1;x<=j;x++)
            for(int y=x;y<=j;y++)
            l2[i][x][y]=i;
            t=j;
        }
    }
    for(int io=1,l,r;io<=q;io++){
        scanf("%d%d",&l,&r);
        int z=-1;
        for(int j=29;j>=0;j--)if(l1[l][j]<=r){z=j;break;}
        printf("%d ",(1<<(z+1))-1);
        vector<int>vp;vp.push_back(l-1),vp.push_back(r+1);
        int kl=32,kr=-1,st=0;
        for(int j=z;j>=0;j--)if(l1[l][j]<=r){
            st|=(1<<j);
            int x=l1[l][j];
            if(l1[x+1][j]>r)vp.push_back(x);
        }
        else kl=min(kl,j),kr=max(kr,j);
        if(kr==-1){puts("0");continue;}
        sort(vp.begin(),vp.end());
        bool oo=0;
        for(int j=0;j+1<vp.size();j++){
            int x=vp[j],y=vp[j+1];if(x==y||x+1==y)continue;
            x++,y--;
            if(l2[x][kl][kr]<=y){oo=1;break;}
        }
        for(int x:vp){
            if(x<l||x>r)continue;
            int sk=st;
            for(int i=0;i<30;i++)if(l1[l][i]==x&&l1[x+1][i]>r)sk^=(1<<i);
            for(int i=0;i<30;i++){
                if((1<<i)>a[x])break;
                if(sk^a[x]^(a[x]-(1<<i))==((1<<(z+1))-1))oo=1;
            }
        }
        if(oo)puts("1");else puts("2");
    }
}
int main(){
    int T;scanf("%d",&T);while(T--)sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5836kb

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: 231ms
memory: 5856kb

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 1
268435455 1
536870911 1
1073741823 1
536870911 1
1073741823 1
536870911 1
1073741823 1
268435455 1
268435455 1
536870911 1
67108863 1
134217727 1
1073741823 1
536870911 1
536870911 1
268435455 1
536870911 1
536870911 1
536870911 1
268435455 1
268435455 1
1073741823 1
16777215 1
10737418...

result:

wrong answer 2nd numbers differ - expected: '2', found: '1'