結果

問題 No.1705 Mode of long array
ユーザー chineristACchineristAC
提出日時 2021-10-08 22:32:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 325 ms / 3,000 ms
コード長 1,697 bytes
コンパイル時間 257 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 101,432 KB
最終ジャッジ日時 2023-09-30 11:26:00
合計ジャッジ時間 16,935 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
74,164 KB
testcase_01 AC 116 ms
74,268 KB
testcase_02 AC 115 ms
73,768 KB
testcase_03 AC 158 ms
81,204 KB
testcase_04 AC 154 ms
80,996 KB
testcase_05 AC 161 ms
81,096 KB
testcase_06 AC 187 ms
81,904 KB
testcase_07 AC 182 ms
81,616 KB
testcase_08 AC 183 ms
81,792 KB
testcase_09 AC 182 ms
82,360 KB
testcase_10 AC 178 ms
81,612 KB
testcase_11 AC 186 ms
81,816 KB
testcase_12 AC 187 ms
81,556 KB
testcase_13 AC 287 ms
93,396 KB
testcase_14 AC 253 ms
89,432 KB
testcase_15 AC 247 ms
83,052 KB
testcase_16 AC 263 ms
83,928 KB
testcase_17 AC 240 ms
82,800 KB
testcase_18 AC 228 ms
83,408 KB
testcase_19 AC 273 ms
86,436 KB
testcase_20 AC 237 ms
84,928 KB
testcase_21 AC 257 ms
92,820 KB
testcase_22 AC 311 ms
96,256 KB
testcase_23 AC 215 ms
81,604 KB
testcase_24 AC 215 ms
81,472 KB
testcase_25 AC 214 ms
81,636 KB
testcase_26 AC 214 ms
81,312 KB
testcase_27 AC 217 ms
81,552 KB
testcase_28 AC 216 ms
81,540 KB
testcase_29 AC 216 ms
81,624 KB
testcase_30 AC 216 ms
81,644 KB
testcase_31 AC 218 ms
81,356 KB
testcase_32 AC 221 ms
81,288 KB
testcase_33 AC 323 ms
98,840 KB
testcase_34 AC 319 ms
98,884 KB
testcase_35 AC 315 ms
98,824 KB
testcase_36 AC 315 ms
98,820 KB
testcase_37 AC 316 ms
98,728 KB
testcase_38 AC 325 ms
99,072 KB
testcase_39 AC 317 ms
98,760 KB
testcase_40 AC 320 ms
98,860 KB
testcase_41 AC 320 ms
99,052 KB
testcase_42 AC 314 ms
98,768 KB
testcase_43 AC 246 ms
100,552 KB
testcase_44 AC 277 ms
101,016 KB
testcase_45 AC 279 ms
100,980 KB
testcase_46 AC 274 ms
101,128 KB
testcase_47 AC 293 ms
100,772 KB
testcase_48 AC 308 ms
101,432 KB
testcase_49 AC 318 ms
99,592 KB
testcase_50 AC 315 ms
99,420 KB
testcase_51 AC 324 ms
100,360 KB
testcase_52 AC 324 ms
100,380 KB
testcase_53 AC 321 ms
99,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        self.size = n
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            k >>= 1
            self.tree[k] = self.segfunc(self.tree[2*k], self.tree[2*k+1])

    def query(self, l, r):
        if r==self.size:
            r = self.num

        res = self.ide_ele

        l += self.num
        r += self.num
        right = []
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                right.append(self.tree[r-1])
            l >>= 1
            r >>= 1

        for e in right[::-1]:
            res = self.segfunc(res,e)
        return res

import sys,random
from collections import deque
from heapq import heappush,heappop

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N,M = mi()
A = li()

Seg = SegmentTree([(0,0)]+[(A[i],i+1) for i in range(M)],max,(-1,-1))

for _ in range(int(input())):
    t,x,y = mi()
    if t==1:
        cnt,val = Seg.tree[Seg.num+x]
        Seg.update(x,(cnt+y,x))
    elif t==2:
        cnt,val = Seg.tree[Seg.num+x]
        Seg.update(x,(cnt-y,x))
    else:
        print(Seg.query(1,M+1)[1])


0