結果

問題 No.1439 Let's Compare!!!!
ユーザー convexineqconvexineq
提出日時 2021-03-26 21:46:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 676 ms / 2,000 ms
コード長 1,665 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 106,268 KB
最終ジャッジ日時 2023-08-19 15:14:42
合計ジャッジ時間 8,463 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,316 KB
testcase_01 AC 62 ms
71,508 KB
testcase_02 AC 62 ms
71,196 KB
testcase_03 AC 62 ms
71,508 KB
testcase_04 AC 64 ms
71,260 KB
testcase_05 AC 63 ms
71,348 KB
testcase_06 AC 60 ms
71,236 KB
testcase_07 AC 136 ms
78,660 KB
testcase_08 AC 153 ms
78,396 KB
testcase_09 AC 122 ms
78,496 KB
testcase_10 AC 643 ms
105,560 KB
testcase_11 AC 676 ms
105,652 KB
testcase_12 AC 646 ms
105,148 KB
testcase_13 AC 652 ms
105,776 KB
testcase_14 AC 676 ms
105,856 KB
testcase_15 AC 631 ms
105,764 KB
testcase_16 AC 629 ms
106,268 KB
testcase_17 AC 667 ms
106,184 KB
testcase_18 AC 603 ms
106,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT: #0-indexed
    __slots__ = ["size", "tree","depth","n0"]
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length()
        self.n0 = 1<<self.depth

    def get_sum(self, i): #a_0 + ... + a_{i} #閉区間
        s = 0; i += 1
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def range_sum(self,l,r): #a_l + ... + a_r 閉区間
        return self.get_sum(r) - self.get_sum(l-1) 

    def range_sum_larger(self,l): #a_l + ... (端まで)
        return self.get_sum(self.size-1) - (self.get_sum(l-1) if l else 0)
    
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def bisect_left(self,w):
        #和が w 以上になる最小の index
        #w が存在しない場合 self.size を返す
        if w <= 0: return 0
        x,k = 0,self.n0
        for _ in range(self.depth):
            k >>= 1
            if x+k <= self.size and self.tree[x+k] < w:
                w -= self.tree[x+k]
                x += k
        return x

n = int(input())
*s, = map(int,input())
*t, = map(int,input())
s.append(0)
t.append(0)

bit = BIT(n)
for i in range(n):
    if s[i] != t[i]: bit.add(i,1)

Q = int(input())
for _ in range(Q):
    c,x,y = input().split()
    i = int(x)-1
    y = int(y)
    eq = s[i]!=t[i]
    if c=="S":
        s[i] = y
    else:
        t[i] = y
    af = s[i]!=t[i]
    if eq != af:
        bit.add(i,af-eq)
    
    i = bit.bisect_left(1)
    if s[i] > t[i]:
        print(">")
    elif s[i] < t[i]:
        print("<")
    else:
        print("=")
0