結果

問題 No.2195 AND Set
ユーザー ntudantuda
提出日時 2023-01-22 12:15:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 735 ms / 2,000 ms
コード長 947 bytes
コンパイル時間 1,169 ms
コンパイル使用メモリ 86,736 KB
実行使用メモリ 100,076 KB
最終ジャッジ日時 2023-09-06 23:03:21
合計ジャッジ時間 13,139 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,316 KB
testcase_01 AC 71 ms
71,200 KB
testcase_02 AC 540 ms
88,480 KB
testcase_03 AC 579 ms
90,568 KB
testcase_04 AC 536 ms
88,748 KB
testcase_05 AC 663 ms
90,252 KB
testcase_06 AC 670 ms
90,172 KB
testcase_07 AC 597 ms
88,936 KB
testcase_08 AC 667 ms
91,380 KB
testcase_09 AC 593 ms
87,524 KB
testcase_10 AC 697 ms
99,432 KB
testcase_11 AC 735 ms
100,052 KB
testcase_12 AC 700 ms
99,888 KB
testcase_13 AC 700 ms
100,024 KB
testcase_14 AC 701 ms
100,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Q = int(input())

D = (1<<30) - 1
N = Q

# N: 処理する区間の長さ
N0 = 2**(N).bit_length()
data = [D]*(2*N0)

# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = data[2*k+1] & data[2*k+2]
# 区間[l, r)のAND
def query(l, r):
    s = D
    L = l + N0; R = r + N0
    while L < R:
        if R & 1:
            R -= 1
            s &= data[R-1]
        if L & 1:
            s &= data[L-1]
            L += 1
        L >>= 1; R >>= 1
    return s

dic = {}

for i in range(Q):
    quer = list(map(int,input().split()))
    if quer[0] == 3:
        if dic:
            print(query(0,N))
        else:
            print(-1)
    else:
        t,u = quer
        if t == 1:
            if u not in dic:
                dic[u] = i
                update(i,u)
        else:
            if u in dic:
                update(dic[u],D)
                dic.pop(u)


0