結果
問題 | No.1439 Let's Compare!!!! |
ユーザー |
👑 ![]() |
提出日時 | 2021-03-28 05:06:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 329 ms / 2,000 ms |
コード長 | 2,274 bytes |
コンパイル時間 | 374 ms |
コンパイル使用メモリ | 82,324 KB |
実行使用メモリ | 126,424 KB |
最終ジャッジ日時 | 2024-11-29 08:57:23 |
合計ジャッジ時間 | 4,400 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 |
ソースコード
import heapqclass Heap_Dict:def __init__(self,Mode=True):"""Mode:True→最小値,False→最大値"""self.heap=[]self.dict={}self.Mode=Modedef __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]+=1else:self.dict[x]=1def erase(self,x):assert (x in self.dict) and (self.dict[x])self.dict[x]-=1while self.heap:y=self.heap[0]if not self.Mode:y=-yif self.dict[y]==0:heapq.heappop(self.heap)else:breakdef is_exist(self,x):return (x in self.dict) and (self.dict[x])def get_min(self):assert self.Modeif self.heap:return self.heap[0]else:return float("inf")def get_max(self):assert not self.Modeif self.heap:return -self.heap[0]else:return -float("inf")def count(self,x):if x not in self.dict:return 0else:return self.dict[x]#================================================import sysinput=sys.stdin.readlinewrite=sys.stdout.writeN=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=[0]*Qfor i in range(Q):c,x,y=input().split()x=int(x);y=int(y)if c=="S":S[x-1]=yelse:T[x-1]=yz=1 if S[x-1]!=T[x-1] else 0if z==1 and U[x-1]==0:U[x-1]=1H.insert(x-1)if z==0 and U[x-1]==1:U[x-1]=0H.erase(x-1)index=H.get_min()if index<N:if S[index]>T[index]:X[i]=0else:X[i]=1else:X[i]=2def g(x):if x==0:return ">"elif x==1:return "<"else:return "="write("\n".join(map(g,X)))