結果

問題 No.2195 AND Set
ユーザー tnakao0123tnakao0123
提出日時 2023-02-26 17:08:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 961 bytes
コンパイル時間 2,008 ms
コンパイル使用メモリ 59,900 KB
実行使用メモリ 7,360 KB
最終ジャッジ日時 2023-10-12 08:05:52
合計ジャッジ時間 6,530 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 99 ms
4,352 KB
testcase_03 AC 112 ms
4,348 KB
testcase_04 AC 103 ms
4,352 KB
testcase_05 AC 106 ms
4,348 KB
testcase_06 AC 106 ms
4,352 KB
testcase_07 AC 88 ms
4,352 KB
testcase_08 AC 105 ms
4,352 KB
testcase_09 AC 85 ms
4,348 KB
testcase_10 AC 133 ms
7,292 KB
testcase_11 AC 133 ms
7,360 KB
testcase_12 AC 132 ms
7,296 KB
testcase_13 AC 134 ms
7,276 KB
testcase_14 AC 131 ms
7,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2195.cc:  No.2195 AND Set - yukicoder
 */

#include<cstdio>
#include<unordered_set>
#include<algorithm>
 
using namespace std;

/* constant */

const int BN = 30;

/* typedef */

/* global variables */

int cs[BN][2];

/* subroutines */

/* main */

int main() {
  int qn;
  scanf("%d", &qn);

  unordered_set<int> xs;
  
  while (qn--) {
    int op;
    scanf("%d", &op);

    if (op == 1) {
      int x;
      scanf("%d", &x);

      if (! xs.count(x)) {
	xs.insert(x);
	for (int i = 0; i < BN; i++)
	  cs[i][(x >> i) & 1]++;
      }
    }
    else if (op == 2) {
      int x;
      scanf("%d", &x);

      if (xs.count(x)) {
	xs.erase(x);
	for (int i = 0; i < BN; i++)
	  cs[i][(x >> i) & 1]--;
      }
    }
    else {
      if (xs.empty()) puts("-1");
      else {
	int s = 0;
	for (int i = 0, bi = 1; i < BN; i++, bi <<= 1)
	  if (cs[i][0] == 0 && cs[i][1] > 0) s |= bi;
	printf("%d\n", s);
      }
    }
  }

  return 0;
}
0