結果

問題 No.1439 Let's Compare!!!!
ユーザー H3PO4H3PO4
提出日時 2021-03-26 21:47:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 743 ms / 2,000 ms
コード長 1,708 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 85,324 KB
最終ジャッジ日時 2023-08-19 15:14:31
合計ジャッジ時間 8,768 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,072 KB
testcase_01 AC 68 ms
71,448 KB
testcase_02 AC 62 ms
71,096 KB
testcase_03 AC 66 ms
71,260 KB
testcase_04 AC 67 ms
71,232 KB
testcase_05 AC 65 ms
71,492 KB
testcase_06 AC 63 ms
71,336 KB
testcase_07 AC 163 ms
79,132 KB
testcase_08 AC 193 ms
78,988 KB
testcase_09 AC 132 ms
78,588 KB
testcase_10 AC 717 ms
85,152 KB
testcase_11 AC 677 ms
84,416 KB
testcase_12 AC 670 ms
84,172 KB
testcase_13 AC 743 ms
84,680 KB
testcase_14 AC 730 ms
85,324 KB
testcase_15 AC 690 ms
84,312 KB
testcase_16 AC 667 ms
84,576 KB
testcase_17 AC 667 ms
84,704 KB
testcase_18 AC 590 ms
83,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    """https://ikatakos.com/pot/programming_algorithm/data_structure/binary_indexed_tree から拝借しています。"""

    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()

    def __getitem__(self, item):
        return self.sum(item) - self.sum(item - 1)

    def initialize(self, A):
        for i, a in enumerate(A, 1):
            self.tree[i] = a
            j = (i & -i) >> 1
            while j:
                self.tree[i] += self.tree[i - j]
                j >>= 1

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def lower_bound(self, x):
        """ 累積和がx以上になる最小のindexと、その直前までの累積和 """
        sum_ = 0
        pos = 0
        for i in range(self.depth, -1, -1):
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1


N = int(input())
S = [int(x) for x in input()]
T = [int(x) for x in input()]

bit = Bit(N)
bit.initialize((int(s != t) for s, t in zip(S, T)))

Q = int(input())
for _ in range(Q):
    c, x, y = input().split()
    x = int(x) - 1
    y = int(y)
    if c == 'S':
        S[x] = y
    else:  # c=='T'
        T[x] = y
    bit.add(x + 1, int(S[x] != T[x]) - bit[x + 1])
    idx = bit.lower_bound(1) - 1
    if idx == N:
        print('=')
    elif S[idx] > T[idx]:
        print('>')
    elif S[idx] < T[idx]:
        print('<')
0