結果
| 問題 | No.1439 Let's Compare!!!! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-03-26 21:47:32 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 743 ms / 2,000 ms | 
| コード長 | 1,708 bytes | 
| コンパイル時間 | 265 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 83,640 KB | 
| 最終ジャッジ日時 | 2024-11-29 08:40:19 | 
| 合計ジャッジ時間 | 8,323 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 17 | 
ソースコード
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('<')
            
            
            
        