結果
問題 | No.2809 Sort Query |
ユーザー | titia |
提出日時 | 2024-07-17 01:28:31 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,908 bytes |
コンパイル時間 | 478 ms |
コンパイル使用メモリ | 81,536 KB |
実行使用メモリ | 184,164 KB |
最終ジャッジ日時 | 2024-07-17 01:29:57 |
合計ジャッジ時間 | 66,240 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
67,328 KB |
testcase_01 | AC | 828 ms
131,200 KB |
testcase_02 | WA | - |
testcase_03 | AC | 793 ms
131,584 KB |
testcase_04 | AC | 790 ms
131,712 KB |
testcase_05 | AC | 813 ms
131,712 KB |
testcase_06 | AC | 828 ms
124,736 KB |
testcase_07 | AC | 800 ms
125,244 KB |
testcase_08 | WA | - |
testcase_09 | AC | 856 ms
125,628 KB |
testcase_10 | WA | - |
testcase_11 | AC | 1,212 ms
178,648 KB |
testcase_12 | AC | 1,149 ms
180,656 KB |
testcase_13 | AC | 1,191 ms
178,324 KB |
testcase_14 | AC | 1,128 ms
178,104 KB |
testcase_15 | WA | - |
testcase_16 | AC | 1,168 ms
178,916 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 1,151 ms
178,296 KB |
testcase_20 | AC | 1,142 ms
179,244 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 770 ms
171,124 KB |
testcase_32 | AC | 786 ms
170,360 KB |
testcase_33 | AC | 784 ms
169,324 KB |
testcase_34 | AC | 774 ms
169,840 KB |
testcase_35 | AC | 761 ms
169,964 KB |
testcase_36 | AC | 853 ms
184,164 KB |
testcase_37 | AC | 873 ms
183,716 KB |
testcase_38 | AC | 860 ms
183,972 KB |
testcase_39 | AC | 887 ms
183,980 KB |
testcase_40 | AC | 868 ms
183,596 KB |
testcase_41 | AC | 582 ms
131,456 KB |
testcase_42 | AC | 603 ms
131,072 KB |
testcase_43 | AC | 574 ms
131,200 KB |
testcase_44 | AC | 609 ms
131,456 KB |
testcase_45 | AC | 580 ms
131,584 KB |
testcase_46 | AC | 542 ms
131,584 KB |
testcase_47 | AC | 524 ms
131,200 KB |
testcase_48 | AC | 555 ms
131,456 KB |
testcase_49 | AC | 534 ms
131,072 KB |
testcase_50 | AC | 551 ms
131,200 KB |
testcase_51 | AC | 544 ms
131,584 KB |
testcase_52 | AC | 418 ms
131,584 KB |
testcase_53 | AC | 551 ms
131,456 KB |
testcase_54 | AC | 384 ms
131,372 KB |
testcase_55 | AC | 390 ms
131,328 KB |
testcase_56 | WA | - |
testcase_57 | AC | 583 ms
114,784 KB |
testcase_58 | AC | 586 ms
114,140 KB |
testcase_59 | WA | - |
testcase_60 | AC | 506 ms
130,276 KB |
testcase_61 | AC | 634 ms
126,404 KB |
testcase_62 | WA | - |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | AC | 429 ms
117,280 KB |
testcase_66 | WA | - |
testcase_67 | AC | 64 ms
67,584 KB |
testcase_68 | AC | 63 ms
67,456 KB |
testcase_69 | WA | - |
testcase_70 | AC | 61 ms
67,456 KB |
ソースコード
import sys input = sys.stdin.readline N,Q=map(int,input().split()) A=list(map(int,input().split())) # https://github.com/tatyam-prime/SortedSet/blob/main/SortedMultiset.py import math from bisect import bisect_left, bisect_right from typing import Generic, Iterable, Iterator, List, Tuple, TypeVar, Optional T = TypeVar('T') class SortedMultiset(Generic[T]): BUCKET_RATIO = 16 SPLIT_RATIO = 24 def __init__(self, a: Iterable[T] = []) -> None: "Make a new SortedMultiset from iterable. / O(N) if sorted / O(N log N)" a = list(a) n = self.size = len(a) if any(a[i] > a[i + 1] for i in range(n - 1)): a.sort() num_bucket = int(math.ceil(math.sqrt(n / self.BUCKET_RATIO))) self.a = [a[n * i // num_bucket : n * (i + 1) // num_bucket] for i in range(num_bucket)] def __iter__(self) -> Iterator[T]: for i in self.a: for j in i: yield j def __reversed__(self) -> Iterator[T]: for i in reversed(self.a): for j in reversed(i): yield j def __eq__(self, other) -> bool: return list(self) == list(other) def __len__(self) -> int: return self.size def __repr__(self) -> str: return "SortedMultiset" + str(self.a) def __str__(self) -> str: s = str(list(self)) return "{" + s[1 : len(s) - 1] + "}" def _position(self, x: T) -> Tuple[List[T], int, int]: "return the bucket, index of the bucket and position in which x should be. self must not be empty." for i, a in enumerate(self.a): if x <= a[-1]: break return (a, i, bisect_left(a, x)) def __contains__(self, x: T) -> bool: if self.size == 0: return False a, _, i = self._position(x) return i != len(a) and a[i] == x def count(self, x: T) -> int: "Count the number of x." return self.index_right(x) - self.index(x) def add(self, x: T) -> None: "Add an element. / O(√N)" if self.size == 0: self.a = [[x]] self.size = 1 return a, b, i = self._position(x) a.insert(i, x) self.size += 1 if len(a) > len(self.a) * self.SPLIT_RATIO: mid = len(a) >> 1 self.a[b:b+1] = [a[:mid], a[mid:]] def _pop(self, a: List[T], b: int, i: int) -> T: ans = a.pop(i) self.size -= 1 if not a: del self.a[b] return ans def discard(self, x: T) -> bool: "Remove an element and return True if removed. / O(√N)" if self.size == 0: return False a, b, i = self._position(x) if i == len(a) or a[i] != x: return False self._pop(a, b, i) return True def lt(self, x: T) -> Optional[T]: "Find the largest element < x, or None if it doesn't exist." for a in reversed(self.a): if a[0] < x: return a[bisect_left(a, x) - 1] def le(self, x: T) -> Optional[T]: "Find the largest element <= x, or None if it doesn't exist." for a in reversed(self.a): if a[0] <= x: return a[bisect_right(a, x) - 1] def gt(self, x: T) -> Optional[T]: "Find the smallest element > x, or None if it doesn't exist." for a in self.a: if a[-1] > x: return a[bisect_right(a, x)] def ge(self, x: T) -> Optional[T]: "Find the smallest element >= x, or None if it doesn't exist." for a in self.a: if a[-1] >= x: return a[bisect_left(a, x)] def __getitem__(self, i: int) -> T: "Return the i-th element." if i < 0: for a in reversed(self.a): i += len(a) if i >= 0: return a[i] else: for a in self.a: if i < len(a): return a[i] i -= len(a) raise IndexError def pop(self, i: int = -1) -> T: "Pop and return the i-th element." if i < 0: for b, a in enumerate(reversed(self.a)): i += len(a) if i >= 0: return self._pop(a, ~b, i) else: for b, a in enumerate(self.a): if i < len(a): return self._pop(a, b, i) i -= len(a) raise IndexError def index(self, x: T) -> int: "Count the number of elements < x." ans = 0 for a in self.a: if a[-1] >= x: return ans + bisect_left(a, x) ans += len(a) return ans def index_right(self, x: T) -> int: "Count the number of elements <= x." ans = 0 for a in self.a: if a[-1] > x: return ans + bisect_right(a, x) ans += len(a) return ans Query=[list(map(int,input().split())) for i in range(Q)] ind=0 while ind<len(Query): if Query[ind][0]==2: break if Query[ind][0]==3: x=Query[ind][1] x-=1 print(A[x]) else: x,k=Query[ind][1],Query[ind][2] x-=1 A[x]=k ind+=1 S=SortedMultiset(A) D=dict() ind+=1 while ind<len(Query): ADD=[] REMOVE=[] D=dict() ind2=-1 while ind<len(Query): if Query[ind][0]==2: ind2=ind break if Query[ind][0]==3: x=Query[ind][1] x-=1 if x in D: print(D[x]) else: print(S[x]) else: x,k=Query[ind][1],Query[ind][2] x-=1 if x in D: REMOVE.append(D[x]) else: REMOVE.append(S[x]) D[x]=k ADD.append(k) ind+=1 for r in REMOVE: S.discard(r) for a in ADD: S.add(a) if ind2==-1: break ind=ind2+1