結果

問題 No.2195 AND Set
ユーザー simansiman
提出日時 2023-01-21 17:16:06
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 1,182 bytes
コンパイル時間 2,214 ms
コンパイル使用メモリ 107,536 KB
実行使用メモリ 8,268 KB
最終ジャッジ日時 2023-09-06 05:50:56
合計ジャッジ時間 9,554 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 292 ms
4,376 KB
testcase_03 AC 334 ms
5,112 KB
testcase_04 AC 286 ms
4,380 KB
testcase_05 AC 353 ms
5,028 KB
testcase_06 AC 340 ms
5,068 KB
testcase_07 AC 305 ms
4,376 KB
testcase_08 AC 342 ms
5,004 KB
testcase_09 AC 296 ms
4,384 KB
testcase_10 AC 407 ms
8,264 KB
testcase_11 AC 386 ms
8,196 KB
testcase_12 AC 392 ms
8,200 KB
testcase_13 AC 383 ms
8,268 KB
testcase_14 AC 384 ms
8,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int Q;
  cin >> Q;
  set<int> S;
  int counter[32];
  memset(counter, 0, sizeof(counter));

  for (int i = 0; i < Q; ++i) {
    int type, x;
    cin >> type;

    if (type == 1) {
      cin >> x;

      if (not S.count(x)) {
        S.insert(x);
        for (int i = 0; i < 32; ++i) {
          if ((x >> i) & 1) {
            counter[i] += 1;
          }
        }
      }
    } else if (type == 2) {
      cin >> x;

      if (S.count(x)) {
        S.erase(x);
        for (int i = 0; i < 32; ++i) {
          if ((x >> i) & 1) {
            counter[i] -= 1;
          }
        }
      }
    } else {
      if (S.empty()) {
        cout << -1 << endl;
      } else {
        ll val = 0;
        for (ll i = 0; i < 32; ++i) {
          if (counter[i] < S.size()) continue;

          if (counter[i] > 0) {
            val += pow(2, i);
          }
        }

        cout << val << endl;
      }
    }
  }

  return 0;
}
0