結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 325 ms
6,940 KB
testcase_03 AC 365 ms
6,940 KB
testcase_04 AC 331 ms
6,944 KB
testcase_05 AC 406 ms
6,944 KB
testcase_06 AC 396 ms
6,944 KB
testcase_07 AC 406 ms
6,940 KB
testcase_08 AC 396 ms
6,940 KB
testcase_09 AC 342 ms
6,944 KB
testcase_10 AC 553 ms
8,064 KB
testcase_11 AC 475 ms
8,192 KB
testcase_12 AC 464 ms
8,192 KB
testcase_13 AC 552 ms
8,192 KB
testcase_14 AC 474 ms
8,064 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