結果

問題 No.1705 Mode of long array
ユーザー ygd.ygd.
提出日時 2021-10-10 12:41:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 481 ms / 3,000 ms
コード長 2,048 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 86,880 KB
実行使用メモリ 93,668 KB
最終ジャッジ日時 2023-10-12 07:57:12
合計ジャッジ時間 19,363 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,340 KB
testcase_01 AC 71 ms
71,164 KB
testcase_02 AC 71 ms
71,272 KB
testcase_03 AC 132 ms
77,404 KB
testcase_04 AC 122 ms
77,648 KB
testcase_05 AC 138 ms
78,484 KB
testcase_06 AC 167 ms
78,212 KB
testcase_07 AC 166 ms
78,352 KB
testcase_08 AC 172 ms
78,152 KB
testcase_09 AC 159 ms
78,552 KB
testcase_10 AC 154 ms
77,900 KB
testcase_11 AC 160 ms
78,256 KB
testcase_12 AC 156 ms
77,976 KB
testcase_13 AC 370 ms
89,828 KB
testcase_14 AC 310 ms
84,084 KB
testcase_15 AC 299 ms
80,488 KB
testcase_16 AC 347 ms
80,464 KB
testcase_17 AC 264 ms
79,496 KB
testcase_18 AC 251 ms
79,328 KB
testcase_19 AC 356 ms
81,412 KB
testcase_20 AC 284 ms
80,440 KB
testcase_21 AC 297 ms
88,200 KB
testcase_22 AC 385 ms
93,224 KB
testcase_23 AC 163 ms
77,788 KB
testcase_24 AC 160 ms
77,980 KB
testcase_25 AC 164 ms
77,568 KB
testcase_26 AC 159 ms
77,828 KB
testcase_27 AC 160 ms
78,112 KB
testcase_28 AC 159 ms
77,832 KB
testcase_29 AC 165 ms
77,852 KB
testcase_30 AC 157 ms
77,972 KB
testcase_31 AC 160 ms
78,016 KB
testcase_32 AC 164 ms
77,768 KB
testcase_33 AC 184 ms
93,424 KB
testcase_34 AC 198 ms
93,328 KB
testcase_35 AC 184 ms
93,240 KB
testcase_36 AC 185 ms
93,376 KB
testcase_37 AC 202 ms
93,304 KB
testcase_38 AC 185 ms
93,304 KB
testcase_39 AC 196 ms
93,252 KB
testcase_40 AC 201 ms
93,436 KB
testcase_41 AC 184 ms
93,384 KB
testcase_42 AC 185 ms
93,584 KB
testcase_43 AC 443 ms
93,248 KB
testcase_44 AC 446 ms
93,316 KB
testcase_45 AC 439 ms
93,356 KB
testcase_46 AC 481 ms
93,260 KB
testcase_47 AC 456 ms
93,668 KB
testcase_48 AC 461 ms
93,304 KB
testcase_49 AC 275 ms
93,484 KB
testcase_50 AC 275 ms
93,304 KB
testcase_51 AC 270 ms
93,216 KB
testcase_52 AC 272 ms
93,480 KB
testcase_53 AC 281 ms
93,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    Tree = SegmentTree([0]*M,max,-1)
    for i in range(M):
        Tree.add(i,A[i]) #0-indexで追加していることに注意

    Q = int(input())
    for _ in range(Q):
        t,x,y = map(int,input().split())
        x -= 1 #0-index
        if t == 1:
            Tree.add(x,y)
        if t == 2:
            Tree.add(x,-y)
        if t == 3:
            mx = Tree.sum(0,M)
            ok = M
            ng = 0
            while abs(ok-ng) > 1:
                mid = (ok+ng)//2
                if Tree.sum(mid,M) < mx: #[mid,M)にmxが入っていない
                    ok = mid
                else:
                    ng = mid
            print(ok) #1indexでおk

if __name__ == '__main__':
    main()
0