結果
| 問題 |
No.1705 Mode of long array
|
| コンテスト | |
| ユーザー |
Kiri8128
|
| 提出日時 | 2021-10-08 23:03:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 489 ms / 3,000 ms |
| コード長 | 784 bytes |
| コンパイル時間 | 163 ms |
| コンパイル使用メモリ | 82,340 KB |
| 実行使用メモリ | 112,188 KB |
| 最終ジャッジ日時 | 2024-07-23 06:26:03 |
| 合計ジャッジ時間 | 20,361 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 51 |
ソースコード
from collections import defaultdict
from heapq import heappush, heappop
HC = defaultdict(int)
H = []
def hpush(x):
heappush(H, -x)
HC[x] += 1
def hpop():
t = -heappop(H)
while not HC[t]:
t = -heappop(H)
HC[t] -= 1
return t
def hmax():
a = hpop()
hpush(a)
return a
def hdel(x):
assert HC[x] > 0
HC[x] -= 1
N, M = map(int, input().split())
A = [int(a) for a in input().split()]
for i, a in enumerate(A):
hpush(a * M + i)
Q = int(input())
for _ in range(Q):
t, x, y = map(int, input().split())
x -= 1
if t == 1:
hdel(A[x] * M + x)
A[x] += y
hpush(A[x] * M + x)
elif t == 2:
hdel(A[x] * M + x)
A[x] -= y
hpush(A[x] * M + x)
else:
print(hmax() % M + 1)
Kiri8128