結果

問題 No.2195 AND Set
ユーザー SSRSSSRS
提出日時 2023-01-20 21:24:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 426 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 1,519 ms
コンパイル使用メモリ 173,192 KB
実行使用メモリ 8,168 KB
最終ジャッジ日時 2023-09-05 13:31:57
合計ジャッジ時間 7,844 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 299 ms
4,384 KB
testcase_03 AC 328 ms
4,920 KB
testcase_04 AC 302 ms
4,376 KB
testcase_05 AC 379 ms
4,864 KB
testcase_06 AC 376 ms
4,860 KB
testcase_07 AC 322 ms
4,380 KB
testcase_08 AC 368 ms
4,924 KB
testcase_09 AC 319 ms
4,380 KB
testcase_10 AC 419 ms
8,168 KB
testcase_11 AC 422 ms
7,984 KB
testcase_12 AC 414 ms
8,100 KB
testcase_13 AC 420 ms
8,028 KB
testcase_14 AC 426 ms
8,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int Q;
  cin >> Q;
  vector<int> C(30, 0);
  int cnt = 0;
  set<int> st;
  for (int i = 0; i < Q; i++){
    int t;
    cin >> t;
    if (t == 1){
      int x;
      cin >> x;
      if (st.count(x) == 0){
        st.insert(x);
        for (int j = 0; j < 30; j++){
          if ((x >> j & 1) == 1){
            C[j]++;
          }
        }
        cnt++;
      }
    }
    if (t == 2){
      int x;
      cin >> x;
      if (st.count(x) == 1){
        st.erase(x);
        for (int j = 0; j < 30; j++){
          if ((x >> j & 1) == 1){
            C[j]--;
          }
        }
        cnt--;
      }
    }
    if (t == 3){
      if (st.empty()){
        cout << -1 << endl;
      } else {
        int ans = 0;
        for (int j = 0; j < 30; j++){
          if (C[j] == cnt){
            ans |= 1 << j;
          }
        }
        cout << ans << endl;
      }
    }
  }
}
0