結果

問題 No.2195 AND Set
ユーザー yansi819yansi819
提出日時 2024-04-11 17:36:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 953 bytes
コンパイル時間 9,758 ms
コンパイル使用メモリ 259,844 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-04-11 17:36:29
合計ジャッジ時間 12,291 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 279 ms
6,944 KB
testcase_03 AC 298 ms
6,940 KB
testcase_04 AC 291 ms
6,940 KB
testcase_05 AC 361 ms
6,944 KB
testcase_06 AC 366 ms
6,944 KB
testcase_07 AC 309 ms
6,940 KB
testcase_08 AC 340 ms
6,940 KB
testcase_09 AC 304 ms
6,940 KB
testcase_10 AC 379 ms
8,192 KB
testcase_11 AC 374 ms
8,192 KB
testcase_12 AC 376 ms
8,192 KB
testcase_13 AC 372 ms
8,192 KB
testcase_14 AC 375 ms
8,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int main() {
  int Q; cin >> Q;
  vector<int> bit(30, 0);
  set<int> st;
  while (Q--) {
    int t; cin >> t;
    if (t == 1) {
      int x; cin >> x;
      if (!st.count(x)) {
        st.insert(x);
        for (int i = 0; i < 30; i++) {
          if (1 & (x >> i)) {
            bit[i]++;
          }
        }
      }
    } else if (t == 2) {
      int x; cin >> x;
      if (st.count(x)) {
        st.erase(x);
        for (int i = 0; i < 30; i++) {
          if (1 & (x >> i)) {
            bit[i]--;
          }
        }
      }
    } else {
      if (st.size() == 0) cout << -1 << endl;
      else {
        int ans = 0;
        for (int i = 0; i < 30; i++) {
          if (bit[i] == st.size()) ans += 1 << i;
        }
        cout << ans << endl;
      }
      
    }
  }
}
0