結果
問題 | No.2650 [Cherry 6th Tune *] セイジャク |
ユーザー | 👑 Kazun |
提出日時 | 2023-07-17 10:44:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 662 ms / 2,500 ms |
コード長 | 3,041 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,132 KB |
実行使用メモリ | 177,812 KB |
最終ジャッジ日時 | 2024-09-29 05:16:12 |
合計ジャッジ時間 | 17,268 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
53,796 KB |
testcase_01 | AC | 36 ms
55,456 KB |
testcase_02 | AC | 201 ms
107,340 KB |
testcase_03 | AC | 184 ms
92,860 KB |
testcase_04 | AC | 533 ms
151,464 KB |
testcase_05 | AC | 421 ms
136,760 KB |
testcase_06 | AC | 256 ms
111,872 KB |
testcase_07 | AC | 437 ms
141,032 KB |
testcase_08 | AC | 207 ms
103,144 KB |
testcase_09 | AC | 658 ms
177,728 KB |
testcase_10 | AC | 645 ms
177,780 KB |
testcase_11 | AC | 641 ms
176,756 KB |
testcase_12 | AC | 658 ms
176,960 KB |
testcase_13 | AC | 662 ms
177,252 KB |
testcase_14 | AC | 652 ms
177,488 KB |
testcase_15 | AC | 661 ms
177,812 KB |
testcase_16 | AC | 514 ms
176,088 KB |
testcase_17 | AC | 511 ms
176,432 KB |
testcase_18 | AC | 509 ms
176,952 KB |
testcase_19 | AC | 520 ms
176,896 KB |
testcase_20 | AC | 520 ms
176,244 KB |
testcase_21 | AC | 499 ms
176,256 KB |
testcase_22 | AC | 496 ms
176,724 KB |
testcase_23 | AC | 479 ms
176,164 KB |
testcase_24 | AC | 471 ms
176,020 KB |
testcase_25 | AC | 468 ms
176,440 KB |
testcase_26 | AC | 478 ms
176,272 KB |
testcase_27 | AC | 465 ms
176,448 KB |
testcase_28 | AC | 470 ms
176,816 KB |
testcase_29 | AC | 467 ms
176,700 KB |
testcase_30 | AC | 442 ms
176,292 KB |
testcase_31 | AC | 511 ms
177,736 KB |
testcase_32 | AC | 226 ms
113,832 KB |
ソースコード
import heapq class Double_Heap: def __init__(self): self.__small=[] self.__large=[] self.__dict={} self.__length=0 self.__sum=0 def __bool__(self): return bool(self.__length) def __len__(self): return self.__length def __contains__(self, x): return self.is_exist(x) def push(self, x): self.__length+=1 self.__sum+=x heapq.heappush(self.__small, x) heapq.heappush(self.__large, -x) if x in self.__dict: self.__dict[x]+=1 else: self.__dict[x]=1 def discard(self, x): """ x を消す (存在しない場合は何もしない). """ if x not in self: return self.__dict[x]-=1 if self.__dict[x]==0: del self.__dict[x] self.__length-=1 self.__sum-=x while self.__small and (self.__small[0] not in self): heapq.heappop(self.__small) while self.__large and (-self.__large[0] not in self): heapq.heappop(self.__large) def is_exist(self, x): """ キューに x が存在するかどうかを判定する. """ return x in self.__dict def get_min(self): assert self return self.__small[0] def pop_min(self): assert self x=self.get_min() self.discard(x) return x def get_max(self): assert self return -self.__large[0] def pop_max(self): assert self x=self.get_max() self.discard(x) return x def count(self, x): """ x の個数を求める. """ return self.__dict.get(x,0) def sum(self): return self.__sum def __str__(self): return str(self.__dict) def __repr__(self): return "[Double Heap]: "+str(self) #================================================== def solve(): N, A = map(int, input().split()) X = list(map(int, input().split())) T = int(input()) E = set(X) Sound = [None] * T for t in range(T): l, r = map(int, input().split()) Sound[t] = (l,r) E.add(l); E.add(r) E_inv = {e:i for i,e in enumerate(sorted(E))} K = len(E_inv) person = [[] for _ in range(K)] for i in range(N): xj = E_inv[X[i]] person[xj].append(i) begin = [[] for _ in range(K)] end = [[] for _ in range(K)] for t,(l,r) in enumerate(Sound,1): lj = E_inv[l]; rj = E_inv[r] begin[lj].append(t) end[rj].append(t) H = Double_Heap() ans = [0] * N for j in range(K): for t in begin[j]: H.push(t) for i in person[j]: if H: ans[i] = H.get_max() else: ans[i] = -1 for t in end[j]: H.discard(t) return ans #================================================== import sys input=sys.stdin.readline write=sys.stdout.write write("\n".join(map(str, solve())))