結果

問題 No.1705 Mode of long array
ユーザー tamatotamato
提出日時 2021-10-08 22:40:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 330 ms / 3,000 ms
コード長 2,985 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 87,616 KB
実行使用メモリ 104,312 KB
最終ジャッジ日時 2023-09-30 11:40:50
合計ジャッジ時間 14,873 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,580 KB
testcase_01 AC 70 ms
71,780 KB
testcase_02 AC 69 ms
71,752 KB
testcase_03 AC 114 ms
78,432 KB
testcase_04 AC 108 ms
77,876 KB
testcase_05 AC 119 ms
77,972 KB
testcase_06 AC 148 ms
79,224 KB
testcase_07 AC 150 ms
78,880 KB
testcase_08 AC 158 ms
79,568 KB
testcase_09 AC 147 ms
79,760 KB
testcase_10 AC 148 ms
79,484 KB
testcase_11 AC 148 ms
79,060 KB
testcase_12 AC 148 ms
78,960 KB
testcase_13 AC 274 ms
98,192 KB
testcase_14 AC 231 ms
93,432 KB
testcase_15 AC 212 ms
80,532 KB
testcase_16 AC 228 ms
81,392 KB
testcase_17 AC 203 ms
80,748 KB
testcase_18 AC 195 ms
81,108 KB
testcase_19 AC 253 ms
85,916 KB
testcase_20 AC 213 ms
83,804 KB
testcase_21 AC 247 ms
104,312 KB
testcase_22 AC 304 ms
99,812 KB
testcase_23 AC 171 ms
78,308 KB
testcase_24 AC 167 ms
78,568 KB
testcase_25 AC 167 ms
78,480 KB
testcase_26 AC 171 ms
78,952 KB
testcase_27 AC 167 ms
78,520 KB
testcase_28 AC 169 ms
78,468 KB
testcase_29 AC 168 ms
78,440 KB
testcase_30 AC 167 ms
78,692 KB
testcase_31 AC 168 ms
78,696 KB
testcase_32 AC 170 ms
78,428 KB
testcase_33 AC 296 ms
99,456 KB
testcase_34 AC 321 ms
99,076 KB
testcase_35 AC 301 ms
99,516 KB
testcase_36 AC 298 ms
99,364 KB
testcase_37 AC 324 ms
99,376 KB
testcase_38 AC 296 ms
99,136 KB
testcase_39 AC 293 ms
99,468 KB
testcase_40 AC 328 ms
99,040 KB
testcase_41 AC 330 ms
99,488 KB
testcase_42 AC 297 ms
99,128 KB
testcase_43 AC 195 ms
98,964 KB
testcase_44 AC 203 ms
99,012 KB
testcase_45 AC 204 ms
99,056 KB
testcase_46 AC 202 ms
98,992 KB
testcase_47 AC 200 ms
98,976 KB
testcase_48 AC 201 ms
98,844 KB
testcase_49 AC 295 ms
99,484 KB
testcase_50 AC 307 ms
99,456 KB
testcase_51 AC 314 ms
99,604 KB
testcase_52 AC 305 ms
99,448 KB
testcase_53 AC 304 ms
99,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline

    def segf(a, b):
        if a[0] > b[0]:
            return a
        elif a[0] < b[0]:
            return b
        else:
            if a[1] > b[1]:
                return a
            else:
                return b

    class SegmentTree:
        def __init__(self, A, initialize=True, segfunc=segf, ident=[-10 ** 60, 0]):
            self.N = len(A)
            self.LV = (self.N - 1).bit_length()
            self.N0 = 1 << self.LV
            self.segfunc = segfunc
            self.ident = ident
            if initialize:
                self.data = [self.ident] * self.N0 + A + [self.ident] * (self.N0 - self.N)
                for i in range(self.N0 - 1, 0, -1):
                    self.data[i] = segfunc(self.data[i * 2], self.data[i * 2 + 1])
            else:
                self.data = [self.ident] * (self.N0 * 2)

        def update(self, i, x):
            i += self.N0 - 1
            self.data[i][0] += x
            for _ in range(self.LV):
                i >>= 1
                self.data[i] = self.segfunc(self.data[i * 2], self.data[i * 2 + 1])

        def get(self, i):
            return self.data[i + self.N0 - 1]

        # open interval [l, r)
        def query(self, l, r):
            l += self.N0 - 1
            r += self.N0 - 1
            ret_l = self.ident
            ret_r = self.ident
            while l < r:
                if l & 1:
                    ret_l = self.segfunc(ret_l, self.data[l])
                    l += 1
                if r & 1:
                    ret_r = self.segfunc(self.data[r - 1], ret_r)
                    r -= 1
                l >>= 1
                r >>= 1
            return self.segfunc(ret_l, ret_r)

        # return smallest i(l <= i < r) s.t. check(A[i]) == True
        def binsearch(self, l, r, check):
            if not check(self.query(l, r)):
                return r
            l += self.N0 - 1
            val = self.ident
            while True:
                if check(self.segfunc(val, self.data[l])):
                    break
                if l & 1:
                    val = self.segfunc(val, self.data[l])
                    l += 1
                l >>= 1
            while l < self.N0:
                newval = self.segfunc(val, self.data[l * 2])
                if not check(newval):
                    val = newval
                    l = (l << 1) + 1
                else:
                    l <<= 1
            return l - self.N0 + 1

    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    AI = [[a, i+1] for i, a in enumerate(A)]
    ST = SegmentTree(AI)
    for _ in range(int(input())):
        t, x, y = map(int, input().split())
        if t == 1:
            ST.update(x, y)
        elif t == 2:
            ST.update(x, -y)
        else:
            _, ans = ST.query(1, M+1)
            print(ans)


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