結果

問題 No.2195 AND Set
ユーザー ineedyourlovepineedyourlovep
提出日時 2023-01-20 21:50:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 439 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 206,440 KB
実行使用メモリ 8,236 KB
最終ジャッジ日時 2023-09-05 14:07:08
合計ジャッジ時間 8,594 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 303 ms
4,376 KB
testcase_03 AC 334 ms
4,896 KB
testcase_04 AC 301 ms
4,376 KB
testcase_05 AC 384 ms
4,800 KB
testcase_06 AC 383 ms
4,896 KB
testcase_07 AC 325 ms
4,380 KB
testcase_08 AC 376 ms
5,012 KB
testcase_09 AC 315 ms
4,380 KB
testcase_10 AC 434 ms
8,236 KB
testcase_11 AC 439 ms
8,028 KB
testcase_12 AC 432 ms
8,000 KB
testcase_13 AC 429 ms
8,184 KB
testcase_14 AC 439 ms
7,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 1000000007;
//const int mod = 998244353;

int main()
{
  int q;
  cin >> q;
  set<ll> st;
  vector<ll> bit(30);
  rep(qi, 0, q) {
    ll t, x;
    cin >> t;
    if (t == 1) {
      cin >> x;
      if (st.count(x)) continue;
      st.insert(x);
      rep(i, 0, 30) if (!(x>>i&1)) bit[i]++;
    }
    else if (t == 2) {
      cin >> x;
      if (st.count(x)) {
        st.erase(x);
        rep(i, 0, 30) if (!(x>>i&1)) bit[i]--;
      }
    }
    else {
      if (!st.size()) cout << -1 << endl;
      else {
        ll tmp = 1;
        ll ans = 0;
        rep(i, 0, 30) {
          if (!bit[i]) ans += tmp;
          tmp *= 2;
        }
        cout << ans << endl;
      }
    }
  }
  return 0;
}
0