結果

問題 No.2195 AND Set
コンテスト
ユーザー SidewaysOwl
提出日時 2023-01-20 23:46:40
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 545 ms / 2,000 ms
+ 339µs
コード長 799 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 248 ms
コンパイル使用メモリ 95,360 KB
実行使用メモリ 112,496 KB
最終ジャッジ日時 2026-07-27 20:34:55
合計ジャッジ時間 8,996 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict
d = defaultdict(int)
q = int(input())
l = [0] *30
cnt = 0
for _ in range(q):
    qr = list(input().split())
    if qr[0] == "1":
        x = int(qr[1])
        if d[x] == 0:
            d[x] = 1
            cnt += 1
            i = 0
            while x:
                if x & 1:l[i] += 1
                x >>= 1
                i += 1
    elif qr[0] == "2":
        x = int(qr[1])
        if d[x] :
            d[x] = 0
            cnt -= 1
            i = 0
            while x:
                if x & 1:l[i] -= 1
                x >>= 1
                i += 1
    else:
        if cnt == 0:print(-1)
        else:
            ans = 0
            for i in range(30):
                if l[i] == cnt:
                    ans += 2 ** i
            print(ans)
    
0