結果

問題 No.1705 Mode of long array
ユーザー H3PO4H3PO4
提出日時 2021-10-08 23:45:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 502 ms / 3,000 ms
コード長 1,335 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 119,856 KB
最終ジャッジ日時 2023-09-30 14:09:06
合計ジャッジ時間 18,558 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,548 KB
testcase_01 AC 94 ms
71,528 KB
testcase_02 AC 96 ms
71,536 KB
testcase_03 AC 140 ms
77,764 KB
testcase_04 AC 122 ms
77,568 KB
testcase_05 AC 145 ms
78,520 KB
testcase_06 AC 176 ms
79,024 KB
testcase_07 AC 180 ms
78,660 KB
testcase_08 AC 180 ms
79,248 KB
testcase_09 AC 169 ms
78,820 KB
testcase_10 AC 173 ms
78,708 KB
testcase_11 AC 179 ms
78,980 KB
testcase_12 AC 176 ms
78,824 KB
testcase_13 AC 324 ms
101,464 KB
testcase_14 AC 272 ms
97,108 KB
testcase_15 AC 251 ms
85,300 KB
testcase_16 AC 273 ms
87,216 KB
testcase_17 AC 251 ms
85,800 KB
testcase_18 AC 225 ms
84,404 KB
testcase_19 AC 295 ms
92,644 KB
testcase_20 AC 256 ms
88,236 KB
testcase_21 AC 308 ms
101,916 KB
testcase_22 AC 360 ms
107,152 KB
testcase_23 AC 236 ms
84,724 KB
testcase_24 AC 236 ms
84,744 KB
testcase_25 AC 236 ms
84,892 KB
testcase_26 AC 236 ms
84,520 KB
testcase_27 AC 236 ms
84,588 KB
testcase_28 AC 241 ms
84,520 KB
testcase_29 AC 235 ms
85,032 KB
testcase_30 AC 254 ms
84,700 KB
testcase_31 AC 241 ms
84,436 KB
testcase_32 AC 242 ms
84,688 KB
testcase_33 AC 410 ms
119,856 KB
testcase_34 AC 398 ms
119,440 KB
testcase_35 AC 400 ms
118,076 KB
testcase_36 AC 397 ms
119,728 KB
testcase_37 AC 409 ms
118,868 KB
testcase_38 AC 405 ms
119,824 KB
testcase_39 AC 403 ms
119,820 KB
testcase_40 AC 405 ms
119,768 KB
testcase_41 AC 402 ms
119,852 KB
testcase_42 AC 410 ms
118,320 KB
testcase_43 AC 236 ms
94,964 KB
testcase_44 AC 237 ms
95,144 KB
testcase_45 AC 238 ms
95,012 KB
testcase_46 AC 237 ms
94,864 KB
testcase_47 AC 251 ms
95,128 KB
testcase_48 AC 249 ms
95,344 KB
testcase_49 AC 498 ms
117,520 KB
testcase_50 AC 487 ms
117,388 KB
testcase_51 AC 502 ms
118,040 KB
testcase_52 AC 490 ms
117,540 KB
testcase_53 AC 481 ms
117,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import heapq
from collections import Counter

input = sys.stdin.buffer.readline


class Counter_min(Counter):
    def __init__(self, iterable=tuple()):
        super(Counter_min, self).__init__(iterable)
        self.h = list(set(iterable))
        heapq.heapify(self.h)

    def add(self, x):
        if x in self:
            self[x] += 1
        else:
            self[x] = 1
            heapq.heappush(self.h, x)

    def remove(self, x):
        if x not in self:
            raise ValueError
        if self[x] == 1:
            del self[x]
        else:
            self[x] -= 1

    def min(self):
        if not super(Counter_min, self).__len__():
            raise ValueError
        while self.h and self.h[0] not in self:
            heapq.heappop(self.h)
        return self.h[0]


N, M = map(int, input().split())
A = list(map(int, input().split()))
ct = Counter_min()
for i, a in enumerate(A):
    ct.add((-a, -i))

Q = int(input())
for _ in range(Q):
    T, X, Y = map(int, input().split())
    if T == 1:
        X -= 1
        ct.remove((-A[X], -X))
        A[X] += Y
        ct.add((-A[X], -X))
    elif T == 2:
        X -= 1
        ct.remove((-A[X], -X))
        A[X] -= Y
        ct.add((-A[X], -X))
    else:
        # assert T == 3
        _, ans = ct.min()
        ans = 1 - ans
        print(ans)
0