結果

問題 No.1439 Let's Compare!!!!
ユーザー rlangevin
提出日時 2023-01-19 22:52:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 120,856 KB
最終ジャッジ日時 2024-06-22 14:57:15
合計ジャッジ時間 5,876 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
from heapq import *

class QuasiBinaryTree:
    def __init__(self, rule="min"):
        if rule == "max":
            self.pm = -1
        else:
            self.pm = 1
 
        self.inf = 10**18
        self.P = [self.inf]
        self.Q = []
 
    def insert(self, x):
        heappush(self.P, x * self.pm)
 
    def erase(self, x):
        heappush(self.Q, x * self.pm)
 
    def top(self):
        while self.Q and (self.P[0] == self.Q[0]):
            heappop(self.P)
            heappop(self.Q)
        return self.P[0] * self.pm
    

N = int(readline())
S = list(input().rstrip())
T = list(input().rstrip())
S = list(map(int, S))
T = list(map(int, T))

BT = QuasiBinaryTree("min")
BT.insert(N)
for i in range(N):
    if S[i] != T[i]:
        BT.insert(i)

Q = int(readline())
for _ in range(Q):
    c, x, y = readline().split()
    x = int(x) - 1
    y = int(y)
    pre = int(S[x] == T[x])
    if c == "S":
        S[x] = y
    else:
        T[x] = y
    now = int(S[x] == T[x])
    if pre != now:
        if now:
            BT.erase(x)
        else:
            BT.insert(x)
    ind = BT.top()
    if ind == N:
        print("=")
    elif S[ind] > T[ind]:
        print(">")
    else:
        print("<")
0