結果
| 問題 | 
                            No.1245 ANDORゲーム(calc)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tnakao0123
                         | 
                    
| 提出日時 | 2020-10-03 12:30:29 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 74 ms / 2,000 ms | 
| コード長 | 1,161 bytes | 
| コンパイル時間 | 694 ms | 
| コンパイル使用メモリ | 94,660 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-18 04:18:03 | 
| 合計ジャッジ時間 | 3,974 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
/* -*- coding: utf-8 -*-
 *
 * 1245.cc:  No.1245 ANDORゲーム(calc) - yukicoder
 */
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;
/* constant */
const int MAX_N = 100000;
const int BN = 30;
/* typedef */
typedef long long ll;
/* global variables */
int as[MAX_N], cs[BN][2];
char s[MAX_N + 4];
/* subroutines */
/* main */
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) scanf("%d", as + i);
  scanf("%s", s);
  for (int k = 0; k < BN; k++)
    for (int x0 = 0; x0 < 2; x0++) {
      for (int i = 0, x = x0; i < n; i++) {
	int bi = (as[i] >> k) & 1;
	int y = (s[i] == '0') ? (x & bi) : (x | bi);
	cs[k][x0] += (x ^ y);
	x = y;
      }
    }
  while (q--) {
    int ti;
    scanf("%d", &ti);
    ll sum = 0;
    for (int k = 0; k < BN; k++)
      sum += (ll)cs[k][(ti >> k) & 1] << k;
    printf("%lld\n", sum);
  }
  return 0;
}
            
            
            
        
            
tnakao0123