結果

問題 No.2195 AND Set
ユーザー SidewaysOwlSidewaysOwl
提出日時 2023-01-20 23:46:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 795 ms / 2,000 ms
コード長 799 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 86,628 KB
実行使用メモリ 109,124 KB
最終ジャッジ日時 2023-09-05 16:14:11
合計ジャッジ時間 11,218 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
70,988 KB
testcase_01 AC 93 ms
71,088 KB
testcase_02 AC 590 ms
86,224 KB
testcase_03 AC 637 ms
86,748 KB
testcase_04 AC 608 ms
86,840 KB
testcase_05 AC 736 ms
87,196 KB
testcase_06 AC 776 ms
90,508 KB
testcase_07 AC 707 ms
89,196 KB
testcase_08 AC 706 ms
87,548 KB
testcase_09 AC 639 ms
86,948 KB
testcase_10 AC 795 ms
104,328 KB
testcase_11 AC 786 ms
109,124 KB
testcase_12 AC 764 ms
103,880 KB
testcase_13 AC 784 ms
106,768 KB
testcase_14 AC 768 ms
104,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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