QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#185923#6631. Maximum Bitwise ORucup-team870#WA 176ms7736kbC++142.1kb2023-09-22 20:23:132023-09-22 20:23:14

Judging History

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

  • [2023-09-22 20:23:14]
  • 评测
  • 测评结果:WA
  • 用时:176ms
  • 内存:7736kb
  • [2023-09-22 20:23:13]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
const int V=29,N=1e5+5,M=500;
int a[N],s1[N][V+1],s2[N][M],q1[V+1],q2[M],lb[N][V+1],pre[N][V+1];
int cal[V+1][V+1];
int wk(){
    int l,r;cin>>l>>r; --l;
    int h=-1,mi=100,ma=-1;
    rep(j,0,V){
        q1[j]=s1[r][j]-s1[l][j];
        if(q1[j])h=j;
    }
    rep(j,0,h){
        if(!q1[j])mi=min(mi,j),ma=max(ma,j);
    }
    cout<<(1<<(h+1))-1<<' ';
    if(h==-1)return 0;
    if(*min_element(q1,q1+h)>0)return 0;
    rep(l,0,V){
        rep(r,l,V){
            int t=cal[l][r]; q2[t]=s2[r][t]-s2[l][t];
        }
    }
    vector<int>vec;
    rep(j,0,h){
        if(q1[j]==1)vec.push_back(pre[r][j]);
    }
    sort(vec.begin(),vec.end());
    // vec.resize(unique(vec.begin(),vec.end())-vec.begin());
    int sz=vec.size();
    int L=0;
    while(L<sz){
        int R=L;
        while(R+1<sz && vec[R+1]==vec[L])++R;
        int i=vec[L];
        if(R-L+1>=2){
            rep(j,0,V){
                if(lb[i][j]!=-1)--q2[cal[lb[i][j]][j]];
            }
        }
        else{
            rep(j,0,V){
                int x=lb[i][j];
                if(x!=-1 && q1[j]!=1)--q2[cal[x][j]];
            }
        }
        L=R+1;
    }
    // cout<<mi<<' '<<ma<<endl;
    rep(l,0,mi){
        rep(r,max(l,ma),V)if(q2[cal[l][r]]>0)return 1;
    }
    return 2;
}
void slv(){
    int n,Q;cin>>n>>Q;
    rep(i,1,n){
        cin>>a[i];
        int h=0;
        rep(j,0,V){
            int v=(a[i]&(1<<j))>0;
            s1[i][j]=s1[i-1][j]+v;
            if(v)pre[i][j]=i,lb[i][j]=h,h=j+1;
            else pre[i][j]=pre[i-1][j],lb[i][j]=-1;
        }
        rep(l,0,V){
            rep(r,l,V)s2[i][cal[l][r]]=s2[i-1][cal[l][r]]+(lb[i][r]==l);
        }
    }
    while(Q--){
        cout<<wk()<<'\n';
    }
}
int main() {
    IOS
    int cnt=0;
    rep(l,0,V){
        rep(r,l,V)cal[l][r]=++cnt;
    }
    int T;cin>>T;
    while(T--)slv();
    return 0;
}
/*
1 
3 1
6 4 2
1 2
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 173ms
memory: 7736kb

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: 176ms
memory: 5680kb

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: 173ms
memory: 5616kb

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 5770th numbers differ - expected: '1', found: '2'