結果

問題 No.1705 Mode of long array
ユーザー kept1994kept1994
提出日時 2022-05-01 12:35:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 454 ms / 3,000 ms
コード長 2,614 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 103,120 KB
最終ジャッジ日時 2023-09-13 04:42:39
合計ジャッジ時間 23,947 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,448 KB
testcase_01 AC 77 ms
71,180 KB
testcase_02 AC 77 ms
71,296 KB
testcase_03 AC 153 ms
78,196 KB
testcase_04 AC 145 ms
78,176 KB
testcase_05 AC 166 ms
78,288 KB
testcase_06 AC 225 ms
79,120 KB
testcase_07 AC 232 ms
79,536 KB
testcase_08 AC 237 ms
78,720 KB
testcase_09 AC 229 ms
78,532 KB
testcase_10 AC 225 ms
79,336 KB
testcase_11 AC 215 ms
79,568 KB
testcase_12 AC 239 ms
79,464 KB
testcase_13 AC 413 ms
97,884 KB
testcase_14 AC 350 ms
88,724 KB
testcase_15 AC 355 ms
80,212 KB
testcase_16 AC 395 ms
81,064 KB
testcase_17 AC 354 ms
80,828 KB
testcase_18 AC 328 ms
80,652 KB
testcase_19 AC 412 ms
83,760 KB
testcase_20 AC 327 ms
82,076 KB
testcase_21 AC 367 ms
95,212 KB
testcase_22 AC 419 ms
103,120 KB
testcase_23 AC 253 ms
79,432 KB
testcase_24 AC 258 ms
79,188 KB
testcase_25 AC 259 ms
78,856 KB
testcase_26 AC 252 ms
79,188 KB
testcase_27 AC 253 ms
79,152 KB
testcase_28 AC 255 ms
79,252 KB
testcase_29 AC 254 ms
79,068 KB
testcase_30 AC 258 ms
79,056 KB
testcase_31 AC 251 ms
79,104 KB
testcase_32 AC 254 ms
79,024 KB
testcase_33 AC 363 ms
97,840 KB
testcase_34 AC 328 ms
97,996 KB
testcase_35 AC 342 ms
97,876 KB
testcase_36 AC 351 ms
98,024 KB
testcase_37 AC 329 ms
97,868 KB
testcase_38 AC 349 ms
97,968 KB
testcase_39 AC 338 ms
97,756 KB
testcase_40 AC 345 ms
97,752 KB
testcase_41 AC 331 ms
97,860 KB
testcase_42 AC 330 ms
97,844 KB
testcase_43 AC 428 ms
97,876 KB
testcase_44 AC 452 ms
97,868 KB
testcase_45 AC 449 ms
97,860 KB
testcase_46 AC 449 ms
98,144 KB
testcase_47 AC 454 ms
97,960 KB
testcase_48 AC 446 ms
97,784 KB
testcase_49 AC 405 ms
97,964 KB
testcase_50 AC 408 ms
97,916 KB
testcase_51 AC 423 ms
97,940 KB
testcase_52 AC 406 ms
97,964 KB
testcase_53 AC 413 ms
97,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys

MOD = 998244353

class SegTree:
    def __init__(self, monoid, bottomList, func):
        self.monoid = monoid
        self.func = func
        self.bottomLen = len(bottomList)
        self.offset = self.bottomLen        # セグ木の最下層の最初のインデックスに合わせるためのオフセット
        self.segLen = self.bottomLen * 2
        self.tree = [monoid] * self.segLen
        self.build(bottomList)

    """
    初期化
    O(self.segLen)
    """
    def build(self, seq):
        # 最下段の初期化
        for i, x in enumerate(seq, self.offset):
            self.tree[i] = x
        # ビルド
        for i in range(self.offset - 1, 0, -1):
            self.tree[i] = self.func(self.tree[i << 1], self.tree[i << 1 | 1])

    """
    一点更新
    O(log(self.bottomLen))
    """
    def pointUpdate(self, i: int, val: int):
        i += self.offset
        self.tree[i] = val
        while i > 1:
            i >>= 1 # 2で割って頂点に達するまで下層から遡上
            self.tree[i] = self.func(self.tree[i << 1], self.tree[i << 1 | 1]) # 必ず末尾0と1がペアになるのでor演算子

    """ 区間取得
    O(log(self.bottomLen))
    """
    def getRange(self, l: int, r: int): # r含まない
        l += self.offset
        r += self.offset
        vL = (self.monoid, 0)
        vR = (self.monoid, 0)
        while l < r:
            if l & 1:
                vL = self.func(vL, self.tree[l])
                l += 1
            if r & 1:
                r -= 1
                vR = self.func(self.tree[r], vR)
            l >>= 1
            r >>= 1
        return self.func(vL, vR)

    """ 一点取得
    O(log(self.bottomLen))
    """
    def getPoint(self, i: int):
        i += self.offset
        return self.tree[i]

def f(x: tuple, y: tuple):
    if x[0] > y[0]:
        return x
    elif x[0] == y[0]:
        if x[1] > y[1]:
            return x
        else:
            return y
    else:
        return y

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    Q = int(input())
    seg = SegTree(0, [(aa, i) for i, aa in enumerate(A)], f)
    for _ in range(Q):
        t, x, y = list(map(int, input().split()))
        if t == 1:
            num, _ = seg.getPoint(x - 1)
            seg.pointUpdate(x - 1, (num + y, x - 1))
        elif t == 2:
            num, _ = seg.getPoint(x - 1)
            seg.pointUpdate(x - 1, (num - y, x - 1))
        else:
            print((seg.getRange(0, M))[1] + 1)
    return

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