結果

問題 No.1245 ANDORゲーム(calc)
ユーザー LayCurseLayCurse
提出日時 2020-10-02 21:39:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 4,197 bytes
コンパイル時間 2,514 ms
コンパイル使用メモリ 211,636 KB
実行使用メモリ 6,044 KB
最終ジャッジ日時 2023-09-23 04:26:13
合計ジャッジ時間 5,939 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 66 ms
5,960 KB
testcase_12 AC 61 ms
5,808 KB
testcase_13 AC 63 ms
5,960 KB
testcase_14 AC 66 ms
5,880 KB
testcase_15 AC 62 ms
5,896 KB
testcase_16 AC 65 ms
5,852 KB
testcase_17 AC 56 ms
5,876 KB
testcase_18 AC 56 ms
5,880 KB
testcase_19 AC 54 ms
5,940 KB
testcase_20 AC 57 ms
5,904 KB
testcase_21 AC 56 ms
5,820 KB
testcase_22 AC 57 ms
5,820 KB
testcase_23 AC 46 ms
6,044 KB
testcase_24 AC 41 ms
5,904 KB
testcase_25 AC 15 ms
5,040 KB
testcase_26 AC 37 ms
5,756 KB
testcase_27 AC 48 ms
5,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
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){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
int Q;
int A[100000];
int T;
char S[100000+2];
int skip[31];
int cnt[31];
int main(){
  int ao_dF3pO;
  int i;
  int b;
  int c;
  int x;
  int y;
  long long res;
  rd(N);
  rd(Q);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  rd(S);
  for(i=(0);i<(N);i++){
    S[i] -= '0';
  }
  for(b=(0);b<(31);b++){
    for(i=(0);i<(N);i++){
      if(((A[i]) &(1<<(b)))){
        x =1;
      }
      else{
        x =0;
      }
      if(x == S[i]){
        break;
      }
    }
    skip[b] = i;
    if(skip[b] < N){
      if(((A[skip[b]]) &(1<<(b)))){
        c =1;
      }
      else{
        c =0;
      }
      for(i=(skip[b]+1);i<(N);i++){
        if(((A[i]) &(1<<(b)))){
          x =1;
        }
        else{
          x =0;
        }
        if(x == S[i] && x != c){
          c = x;
          cnt[b]++;
        }
      }
    }
  }
  int tU__gIr_ = Q;
  for(ao_dF3pO=(0);ao_dF3pO<(tU__gIr_);ao_dF3pO++){
    res = 0;
    rd(T);
    for(b=(0);b<(31);b++){
      res += cnt[b] * (1LL<<b);
      if(skip[b] < N){
        if(((A[skip[b]]) &(1<<(b)))){
          x =1;
        }
        else{
          x =0;
        }
        if(((T) &(1<<(b)))){
          y =1;
        }
        else{
          y =0;
        }
        if(x != y){
          res += (1LL<<b);
        }
      }
    }
    wt_L(res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200926-1

// --- original code ---
// int N, Q, A[1d5], T;
// char S[1d5+2];
// 
// int skip[31], cnt[31];
// 
// {
//   int i, b, c, x, y;
//   ll res;
//   rd(N,Q,A(N),S);
//   rep(i,N) S[i] -= '0';
// 
//   rep(b,31){
//     rep(i,N){
//       x = if[BIT_ith(A[i],b), 1, 0];
//       if(x == S[i]) break;
//     }
//     skip[b] = i;
// 
//     if(skip[b] < N){
//       c = if[BIT_ith(A[skip[b]],b), 1, 0];
//       rep(i,skip[b]+1,N){
//         x = if[BIT_ith(A[i],b), 1, 0];
//         if(x == S[i] && x != c) c = x, cnt[b]++; 
//       }
//     }
//   }
// 
//   REP(Q){
//     res = 0;
//     rd(T);
//     rep(b,31){
//       res += cnt[b] * (1LL<<b);
//       if(skip[b] < N){
//         x = if[BIT_ith(A[skip[b]],b), 1, 0];
//         y = if[BIT_ith(T,b), 1, 0];
//         if(x != y) res += (1LL<<b);
//       }
//     }
//     wt(res);
//   }
// }
0