結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー ntudantuda
提出日時 2023-05-21 12:19:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,963 ms / 2,000 ms
コード長 1,344 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 136,276 KB
最終ジャッジ日時 2023-08-23 15:02:14
合計ジャッジ時間 68,883 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,140 KB
testcase_01 AC 1,617 ms
107,940 KB
testcase_02 AC 1,811 ms
120,812 KB
testcase_03 AC 1,710 ms
102,052 KB
testcase_04 AC 1,647 ms
111,388 KB
testcase_05 AC 1,753 ms
109,740 KB
testcase_06 AC 1,757 ms
132,856 KB
testcase_07 AC 1,851 ms
123,020 KB
testcase_08 AC 1,874 ms
126,704 KB
testcase_09 AC 1,893 ms
126,240 KB
testcase_10 AC 1,736 ms
107,460 KB
testcase_11 AC 1,814 ms
121,272 KB
testcase_12 AC 1,837 ms
115,428 KB
testcase_13 AC 1,800 ms
120,496 KB
testcase_14 AC 1,820 ms
115,816 KB
testcase_15 AC 1,763 ms
122,884 KB
testcase_16 AC 1,843 ms
122,480 KB
testcase_17 AC 1,791 ms
125,760 KB
testcase_18 AC 1,848 ms
117,932 KB
testcase_19 AC 1,790 ms
122,208 KB
testcase_20 AC 1,775 ms
114,420 KB
testcase_21 AC 1,963 ms
135,860 KB
testcase_22 AC 1,922 ms
136,276 KB
testcase_23 AC 1,887 ms
135,900 KB
testcase_24 AC 1,890 ms
135,816 KB
testcase_25 AC 1,926 ms
135,492 KB
testcase_26 AC 1,885 ms
134,564 KB
testcase_27 AC 1,925 ms
135,812 KB
testcase_28 AC 1,897 ms
135,920 KB
testcase_29 AC 1,881 ms
135,936 KB
testcase_30 AC 1,895 ms
135,896 KB
testcase_31 AC 1,398 ms
131,744 KB
testcase_32 AC 1,446 ms
132,100 KB
testcase_33 AC 1,606 ms
133,064 KB
testcase_34 AC 1,415 ms
133,292 KB
testcase_35 AC 1,485 ms
134,752 KB
testcase_36 AC 1,456 ms
133,168 KB
testcase_37 AC 334 ms
81,672 KB
testcase_38 AC 1,815 ms
123,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 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)の区間和
def query(l, r):
    s = 0
    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

def search(x):
    lb = 0
    ub = N
    while ub - lb > 1:
        mid = (lb + ub) // 2
        if query(0, mid) <= x:
            lb = mid
        else:
            ub = mid
    return lb

T = int(input())
for t in range(T):
    N = int(input())
    X = [True if x == "True" else False for x in input().split()]
    Y = input().split()
    S = list(map(int, input().split()))

    # N: セグ木処理する区間の長さ
    N0 = 2 ** (N + 1).bit_length()
    data = [0] * (2 * N0)
    for i in range(N):
        update(i, 1)
    for s in S:
        r = search(s)
        l = search(s - 1)
        if Y[l] == "and":
            X[r] &= X[l]
        elif Y[l] == "or":
            X[r] |= X[l]
        elif Y[l] == "xor":
            X[r] ^= X[l]
        else:
            if X[l] == False:
                X[r] = True
        update(l, 0)
    print(X[r])
0