結果

問題 No.1439 Let's Compare!!!!
ユーザー ygd.ygd.
提出日時 2021-03-26 21:58:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,402 ms / 2,000 ms
コード長 2,215 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 87,968 KB
最終ジャッジ日時 2023-08-19 15:19:17
合計ジャッジ時間 14,542 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,268 KB
testcase_01 AC 70 ms
71,556 KB
testcase_02 AC 67 ms
71,120 KB
testcase_03 AC 69 ms
71,244 KB
testcase_04 AC 78 ms
75,880 KB
testcase_05 AC 71 ms
71,248 KB
testcase_06 AC 68 ms
71,376 KB
testcase_07 AC 170 ms
78,624 KB
testcase_08 AC 192 ms
79,304 KB
testcase_09 AC 150 ms
78,592 KB
testcase_10 AC 1,106 ms
87,292 KB
testcase_11 AC 1,334 ms
87,656 KB
testcase_12 AC 1,312 ms
87,736 KB
testcase_13 AC 1,163 ms
87,516 KB
testcase_14 AC 1,198 ms
87,048 KB
testcase_15 AC 1,369 ms
87,736 KB
testcase_16 AC 1,370 ms
87,696 KB
testcase_17 AC 1,402 ms
87,968 KB
testcase_18 AC 855 ms
87,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def segfunc(x,y):
  return x+y

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

N = int(input())
S = str(input()); S = [int(s) for s in S] #大きい1
T = str(input()); T = [int(t) for t in T] #大きい2

Tree = SegmentTree([0]*(N+1),segfunc,0)
for i in range(N):
    keta = i+1
    if S[i] > T[i]:
        Tree.update(keta,1)
    elif T[i] > S[i]:
        Tree.update(keta,2)
Q = int(input())
for _ in range(Q):
    Flag, x, y = input().split()
    x = int(x) - 1 #0index
    y = int(y)
    if Flag == "S":
        S[x] = y
    else:
        T[x] = y
    #print(S,T)
    if S[x] > T[x]:
        Tree.update(x+1,1)
    elif T[x] > S[x]:
        Tree.update(x+1,2)
    else:
        Tree.update(x+1,0)
    if Tree.sum(0,N+1) == 0:
        print("=")
    else:
        ok = 1
        ng = N+1
        while abs(ok-ng) > 1:
            mid = (ok+ng)//2
            if Tree.sum(0,mid) == 0:
                ok = mid
            else:
                ng = mid
        #print(ok,Tree.__getitem__(ok))
        if Tree.__getitem__(ok) == 1:
            print(">")
        else:
            print("<")
0