結果

問題 No.911 ラッキーソート
ユーザー LayCurseLayCurse
提出日時 2019-10-18 22:07:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 5,305 bytes
コンパイル時間 2,412 ms
コンパイル使用メモリ 210,876 KB
実行使用メモリ 5,136 KB
最終ジャッジ日時 2023-09-07 23:35:34
合計ジャッジ時間 6,578 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 101 ms
4,928 KB
testcase_14 AC 99 ms
5,068 KB
testcase_15 AC 96 ms
4,900 KB
testcase_16 AC 97 ms
4,868 KB
testcase_17 AC 97 ms
4,936 KB
testcase_18 AC 96 ms
4,896 KB
testcase_19 AC 97 ms
4,944 KB
testcase_20 AC 90 ms
4,936 KB
testcase_21 AC 81 ms
4,864 KB
testcase_22 AC 73 ms
4,880 KB
testcase_23 AC 69 ms
4,720 KB
testcase_24 AC 62 ms
4,640 KB
testcase_25 AC 36 ms
4,380 KB
testcase_26 AC 31 ms
4,380 KB
testcase_27 AC 13 ms
4,376 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 100 ms
5,136 KB
testcase_39 AC 72 ms
4,824 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 92 ms
5,004 KB
testcase_42 AC 52 ms
4,376 KB
testcase_43 AC 100 ms
4,944 KB
testcase_44 AC 16 ms
4,952 KB
testcase_45 AC 35 ms
4,948 KB
testcase_46 AC 50 ms
4,952 KB
testcase_47 AC 21 ms
4,948 KB
testcase_48 AC 13 ms
4,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned x){
  int s=0;
  char f[10];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned long long x){
  int s=0;
  char f[21];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(double x){
  printf("%.15f",x);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
inline void wt_L(string &x){
  int i=0;
  for(i=0;x[i]!='\0';i++){
    putchar_unlocked(x[i]);
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
long long LL;
long long RR;
long long A[200000];
int cond[62];
int L[62];
int R[62];
void doit(int k, int a, int b){
  int i;
  int mn0;
  int mx0;
  int mn1;
  int mx1;
  if(k < 0){
    return;
  }
  mn0 = mn1 = 1073709056;
  mx0 = mx1 = -1073709056;
  for(i=(a);i<(b+1);i++){
    if(A[i] & (1LL<<k)){
      chmin(mn1, i);
      chmax(mx1, i);
    }
    else{
      chmin(mn0, i);
      chmax(mx0, i);
    }
  }
  if(mn0 == 1073709056 || mn1 == 1073709056){
    doit(k-1, a, b);
    return;
  }
  if(mx0 < mn1){
    cond[k] |= 2;
    doit(k-1, a, mx0);
    doit(k-1, mn1, b);
  }
  else if(mx1 < mn0){
    cond[k] |= 1;
    doit(k-1, a, mx1);
    doit(k-1, mn0, b);
  }
  else{
    cond[k] |= 3;
  }
}
long long dp[2][2][62];
long long solve(int x, int y, int d){
  int sx;
  int sy;
  long long res = 0;
  if(d < 0){
    return 1;
  }
  if(dp[x][y][d] >= 0){
    return dp[x][y][d];
  }
  if(!((cond[d]) &(1<<(0)))&& (L[d]==0 || x)){
    sy = y;
    if(R[d]==1){
      sy = 1;
    }
    res += solve(x, sy, d-1);
  }
  if(!((cond[d]) &(1<<(1)))&& (R[d]==1 || y)){
    sx = x;
    if(L[d]==0){
      sx = 1;
    }
    res += solve(sx, y, d-1);
  }
  return dp[x][y][d] = res;
}
int main(){
  int i;
  int k;
  int mn0;
  int mx0;
  int mn1;
  int mx1;
  rd(N);
  rd(LL);
  rd(RR);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(62);i++){
    if(LL&(1LL<<i)){
      L[i] = 1;
    }
  }
  for(i=(0);i<(62);i++){
    if(RR&(1LL<<i)){
      R[i] = 1;
    }
  }
  doit(61, 0, N-1);
  for(i=(0);i<(2);i++){
    int j;
    for(j=(0);j<(2);j++){
      for(k=(0);k<(62);k++){
        dp[i][j][k] = -1;
      }
    }
  }
  wt_L(solve(0,0,61));
  wt_L('\n');
  return 0;
}
// cLay varsion 20191012-1

// --- original code ---
// int N; ll LL, RR;
// ll A[2d5];
// 
// int cond[62];
// int L[62], R[62];
// 
// void doit(int k, int a, int b){
//   int mn0, mx0, mn1, mx1;
//   if(k < 0) return;
//   mn0 = mn1 = int_inf;
//   mx0 = mx1 = -int_inf;
//   rep(i,a,b+1){
//     if(A[i] & (1LL<<k)){
//       mn1 <?= i;
//       mx1 >?= i;
//     } else {
//       mn0 <?= i;
//       mx0 >?= i;
//     }
//   }
//   if(mn0 == int_inf || mn1 == int_inf) doit(k-1, a, b), return;
//   if(mx0 < mn1){
//     cond[k] |= 2;
//     doit(k-1, a, mx0);
//     doit(k-1, mn1, b);
//   } else if(mx1 < mn0){
//     cond[k] |= 1;
//     doit(k-1, a, mx1);
//     doit(k-1, mn0, b);
//   } else {
//     cond[k] |= 3;
//   }
// }
// 
// ll dp[2][2][62];
// ll solve(int x, int y, int d){
//   int sx, sy;
//   ll res = 0;
//   if(d < 0) return 1;
//   if(dp[x][y][d] >= 0) return dp[x][y][d];
//   if(!BIT_ith(cond[d],0) && (L[d]==0 || x)){
//     sy = y;
//     if(R[d]==1) sy = 1;
//     res += solve(x, sy, d-1);
//   }
//   if(!BIT_ith(cond[d],1) && (R[d]==1 || y)){
//     sx = x;
//     if(L[d]==0) sx = 1;
//     res += solve(sx, y, d-1);
//   }
//   return dp[x][y][d] = res;
// }
// 
// {
//   int k, mn0, mx0, mn1, mx1;
//   rd(N,LL,RR,A(N));
//   rep(i,62) if(LL&(1LL<<i)) L[i] = 1;
//   rep(i,62) if(RR&(1LL<<i)) R[i] = 1;
//   doit(61, 0, N-1);
//   rep(i,2) rep(j,2) rep(k,62) dp[i][j][k] = -1;
//   wt(solve(0,0,61));
// }
0