QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#134891#6631. Maximum Bitwise ORRd_rainydays#WA 41ms20164kbC++202.0kb2023-08-05 09:46:482023-08-05 09:46:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 09:46:52]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:20164kb
  • [2023-08-05 09:46:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;++i)

void Rd(int &x){
  char c;x=0;
  while((c=getchar())<'0');
  do
  {
    x=(x<<3)+(x<<1)+(c^'0');
    /* code */
  } while ((c=getchar())>='0');
  
}

static const int M=100003;

int T,n,q;
int S[M][31],A[M];
int Ans[M],tim[M],R[M];
vector<int>Q[M];
int MX[31][M];
int main(){
  Rd(T);
  while(T--){
    Rd(n),Rd(q);
    REP(i,1,n+1){
      int x;
      Rd(x);A[i]=x;
      REP(j,0,31)S[i][j]=S[i-1][j]+((x>>j)&1);
    }
    REP(i,1,n+1)Q[i].clear();
    REP(j,0,31)REP(i,1,n+1)MX[j][i]=0;

    REP(i,0,q){
      int l,r;
      Rd(l),Rd(r);
      Ans[i]=tim[i]=-1;
      for(int j=30;j>=0;--j){
        if(S[r][j]-S[l-1][j]){
          Ans[i]=j;
          bool f=1;
          for(int k=j-1;k>=0;--k){
            f&=(S[r][k]-S[l-1][k])>0;
            //cout<<S[r][k]<<','<<S[l-1][k]<<endl;
          }
          tim[i]=f?0:2;
          break;
        }
      }
      if(tim[i]==2){
        Q[l].push_back(i);
        R[i]=r;
      }
    }
    for(int i=n;i>=1;--i){
      int lt=-1,a=A[i];
      for(int j=0;j<=30;++j){
        if((a>>j)&1){
          if(lt!=j-1){
            lt++;
            int u=i;
            while(u<=n)
              MX[lt][u]=max(MX[lt][u],j),u+=u&-u;
          }
          lt=j;
        }
      }
      for(auto p:Q[i]){
        int r=R[p],lp=-1,rp=-1;
        for(int j=0;j<=Ans[p];++j)
          if(S[r][j]-S[i-1][j]==0){
            lp=j;break;
          }
        for(int j=Ans[p];j>=0;--j)
          if(S[r][j]-S[i-1][j]==0){
            rp=j;break;
          }
        for(int j=0;j<=lp;++j){
          int u=r,mx=0;
          while(u)
            mx=max(mx,MX[j][u]),u^=u&-u;
          //cerr<<i<<','<<p<<','<<j<<','<<mx<<','<<rp<<endl;
          if(mx>rp){
            tim[p]=1;
            break;
          }
        }
      }
    }
    REP(i,0,q)if(Ans[i]==-1)puts("0 0");
    else printf("%d %d\n",(1<<Ans[i]+1)-1,tim[i]);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 20164kb

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: 41ms
memory: 20036kb

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: 31ms
memory: 18128kb

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'