結果

問題 No.1439 Let's Compare!!!!
ユーザー 👑 KazunKazun
提出日時 2021-03-28 05:08:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 2,167 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 126,600 KB
最終ジャッジ日時 2024-05-06 22:34:15
合計ジャッジ時間 4,249 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,120 KB
testcase_01 AC 39 ms
53,376 KB
testcase_02 AC 38 ms
53,120 KB
testcase_03 AC 38 ms
52,608 KB
testcase_04 AC 38 ms
53,760 KB
testcase_05 AC 39 ms
52,992 KB
testcase_06 AC 37 ms
53,248 KB
testcase_07 AC 84 ms
77,056 KB
testcase_08 AC 86 ms
77,080 KB
testcase_09 AC 65 ms
70,784 KB
testcase_10 AC 322 ms
125,200 KB
testcase_11 AC 272 ms
100,032 KB
testcase_12 AC 251 ms
100,992 KB
testcase_13 AC 323 ms
126,356 KB
testcase_14 AC 330 ms
126,600 KB
testcase_15 AC 246 ms
99,456 KB
testcase_16 AC 211 ms
99,964 KB
testcase_17 AC 244 ms
99,456 KB
testcase_18 AC 163 ms
99,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
class Heap_Dict:
    def __init__(self,Mode=True):
        """

        Mode:True→最小値,False→最大値
        """
        self.heap=[]
        self.dict={}
        self.Mode=Mode

    def __bool__(self):
        return bool(self.heap)

    def insert(self,x):
        if self.Mode and not self.is_exist(x):
            heapq.heappush(self.heap,x)
        elif not self.Mode and not self.is_exist(x):
            heapq.heappush(self.heap,-x)

        if x in self.dict:
            self.dict[x]+=1
        else:
            self.dict[x]=1

    def erase(self,x):
        assert (x in self.dict) and (self.dict[x])

        self.dict[x]-=1

        while self.heap:
            y=self.heap[0]
            if not self.Mode:y=-y
            if self.dict[y]==0:
                heapq.heappop(self.heap)
            else:
                break

    def is_exist(self,x):
        return (x in self.dict) and (self.dict[x])

    def get_min(self):
        assert self.Mode

        if self.heap:
            return self.heap[0]
        else:
            return float("inf")

    def get_max(self):
        assert not self.Mode

        if self.heap:
            return -self.heap[0]
        else:
            return -float("inf")

    def count(self,x):
        if x not in self.dict:
            return 0
        else:
            return self.dict[x]
#================================================
import sys
input=sys.stdin.readline
write=sys.stdout.write

N=int(input())
S=list(map(int,input()[:-1]))
T=list(map(int,input()[:-1]))

U=[1 if S[i]!=T[i] else 0 for i in range(N)]
H=Heap_Dict()
H.insert(N)
for i in range(N):
    if U[i]:
        H.insert(i)

Q=int(input())
X=[""]*Q
for i in range(Q):
    c,x,y=input().split()
    x=int(x);y=int(y)

    if c=="S":
        S[x-1]=y
    else:
        T[x-1]=y

    z=1 if S[x-1]!=T[x-1] else 0

    if z==1 and U[x-1]==0:
        U[x-1]=1
        H.insert(x-1)
    if z==0 and U[x-1]==1:
        U[x-1]=0
        H.erase(x-1)

    index=H.get_min()

    if index<N:
        if S[index]>T[index]:
            X[i]=">"
        else:
            X[i]="<"
    else:
        X[i]="="

write("\n".join(X))
0