結果

問題 No.2195 AND Set
ユーザー FromBooskaFromBooska
提出日時 2023-08-31 13:50:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 769 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 551 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 91,024 KB
最終ジャッジ日時 2023-08-31 13:50:25
合計ジャッジ時間 11,770 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,252 KB
testcase_01 AC 72 ms
71,060 KB
testcase_02 AC 599 ms
81,944 KB
testcase_03 AC 699 ms
83,972 KB
testcase_04 AC 605 ms
84,076 KB
testcase_05 AC 769 ms
84,784 KB
testcase_06 AC 742 ms
85,004 KB
testcase_07 AC 711 ms
82,248 KB
testcase_08 AC 765 ms
85,044 KB
testcase_09 AC 624 ms
79,848 KB
testcase_10 AC 769 ms
90,032 KB
testcase_11 AC 746 ms
89,944 KB
testcase_12 AC 757 ms
91,024 KB
testcase_13 AC 766 ms
89,360 KB
testcase_14 AC 739 ms
90,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# セグメントツリーでできたが前回の方法でもやってみる
# 30桁しかないのでそれぞれの桁に1が何回出たかカウントすればいい

Q = int(input())
one_count = [0]*30
S = set()
count = 0
for q in range(Q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        x = query[1]
        if x not in S:
            S.add(x)
            count += 1
            for i in range(30):
                if x>>i&1 == 1:
                    one_count[i] += 1
    elif query[0] == 2:
        x = query[1]
        if x in S:
            S.discard(x)
            count -= 1
            for i in range(30):
                if x>>i&1 == 1:
                    one_count[i] -= 1
    elif query[0] == 3:
        if count > 0:
            ans = 0
            for d in range(30):
                if one_count[d] == count:
                    ans += pow(2, d)
            print(ans)
        else:
            print(-1)
    #print('q', q, 'count', count)
    #print('one_count', one_count)
0