結果

問題 No.1245 ANDORゲーム(calc)
ユーザー risujirohrisujiroh
提出日時 2020-10-02 21:54:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 2,065 bytes
コンパイル時間 4,496 ms
コンパイル使用メモリ 375,312 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 04:50:49
合計ジャッジ時間 8,368 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 3 ms
4,372 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 84 ms
4,376 KB
testcase_12 AC 83 ms
4,376 KB
testcase_13 AC 83 ms
4,376 KB
testcase_14 AC 84 ms
4,376 KB
testcase_15 AC 84 ms
4,376 KB
testcase_16 AC 84 ms
4,372 KB
testcase_17 AC 69 ms
4,376 KB
testcase_18 AC 64 ms
4,372 KB
testcase_19 AC 62 ms
4,376 KB
testcase_20 AC 71 ms
4,376 KB
testcase_21 AC 69 ms
4,380 KB
testcase_22 AC 63 ms
4,372 KB
testcase_23 AC 78 ms
4,372 KB
testcase_24 AC 76 ms
4,376 KB
testcase_25 AC 32 ms
4,376 KB
testcase_26 AC 33 ms
4,376 KB
testcase_27 AC 40 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt")
// #define NDEBUG

#include <bits/extc++.h>
#include <x86intrin.h>

struct rep {
  struct iter {
    int i;
    constexpr void operator++() { ++i; }
    constexpr int operator*() const { return i; }
    friend constexpr bool operator!=(iter a, iter b) { return *a != *b; }
  };
  const int l, r;
  constexpr rep(int _l, int _r) : l(std::min(_l, _r)), r(_r) {}
  constexpr rep(int n) : rep(0, n) {}
  constexpr iter begin() const { return {l}; }
  constexpr iter end() const { return {r}; }
};
struct per {
  struct iter {
    int i;
    constexpr void operator++() { --i; }
    constexpr int operator*() const { return i; }
    friend constexpr bool operator!=(iter a, iter b) { return *a != *b; }
  };
  const int l, r;
  constexpr per(int _l, int _r) : l(std::min(_l, _r)), r(_r) {}
  constexpr per(int n) : per(0, n) {}
  constexpr iter begin() const { return {r - 1}; }
  constexpr iter end() const { return {l - 1}; }
};
template <class T, class U>
constexpr bool chmin(T& a, U&& b) {
  return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U>
constexpr bool chmax(T& a, U&& b) {
  return a < b ? a = std::forward<U>(b), true : false;
}

int main() {
  using namespace std;
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (auto&& e : a) cin >> e;
  string s;
  cin >> s;
  vector v(2, vector<int64_t>(30));
  for (int k : rep(2))
    for (int d : rep(30)) {
      int x = k << d;
      for (int i : rep(n))
        if (s[i] & 1) {
          if (~x >> d & 1 and a[i] >> d & 1) {
            x = 1 << d;
            v[k][d] += 1 << d;
          }
        } else {
          if (x >> d & 1 and ~a[i] >> d & 1) {
            x = 0;
            v[k][d] += 1 << d;
          }
        }
    }
  while (q--) {
    int t;
    cin >> t;
    int64_t ans{};
    for (int d : rep(30)) ans += v[t >> d & 1][d];
    cout << ans << '\n';
  }
}
0