結果
問題 | No.1245 ANDORゲーム(calc) |
ユーザー |
|
提出日時 | 2020-10-02 22:26:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 1,470 bytes |
コンパイル時間 | 1,701 ms |
コンパイル使用メモリ | 173,204 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-17 21:56:44 |
合計ジャッジ時間 | 4,634 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;constexpr char newl = '\n';int main() {cin.tie(nullptr);ios::sync_with_stdio(false);int n, q;cin >> n >> q;vector< vector<ll> > dp(2, vector<ll>(30, 0));vector< vector<ll> > memo(2, vector<ll>(30, 0));for (int i = 0; i < 30; i++) {memo[1][i] = (1LL << i);}vector<ll> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}string s;cin >> s;for (int i = 0; i < n; i++) {if (s[i] == '0') {for (int j = 0; j < 30; j++) {ll bit = (a[i] & (1LL << j));for (int k = 0; k < 2; k++) {ll nex = (memo[k][j] & bit);dp[k][j] += memo[k][j] - nex;memo[k][j] = nex;}}} else {for (int j = 0; j < 30; j++) {ll bit = (a[i] & (1LL << j));for (int k = 0; k < 2; k++) {ll nex = (memo[k][j] | bit);dp[k][j] += nex - memo[k][j];memo[k][j] = nex;}}}}for (int i = 0; i < q; i++) {ll t;cin >> t;ll ans = 0;for (int j = 0; j < 30; j++) {ans += dp[t >> j & 1][j];// cerr << dp[t >> j & 1][j] << " ";}cout << ans << newl;}return 0;}