結果

問題 No.1705 Mode of long array
ユーザー tktk_snsntktk_snsn
提出日時 2021-10-08 23:07:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 213 ms / 3,000 ms
コード長 3,806 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 99,432 KB
最終ジャッジ日時 2023-09-30 12:36:35
合計ジャッジ時間 11,688 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,588 KB
testcase_01 AC 75 ms
71,488 KB
testcase_02 AC 76 ms
71,296 KB
testcase_03 AC 101 ms
76,896 KB
testcase_04 AC 96 ms
76,900 KB
testcase_05 AC 104 ms
76,996 KB
testcase_06 AC 123 ms
78,168 KB
testcase_07 AC 125 ms
78,152 KB
testcase_08 AC 123 ms
78,304 KB
testcase_09 AC 123 ms
78,304 KB
testcase_10 AC 119 ms
78,052 KB
testcase_11 AC 121 ms
78,176 KB
testcase_12 AC 122 ms
78,168 KB
testcase_13 AC 189 ms
95,292 KB
testcase_14 AC 168 ms
86,932 KB
testcase_15 AC 162 ms
80,608 KB
testcase_16 AC 169 ms
80,160 KB
testcase_17 AC 158 ms
79,584 KB
testcase_18 AC 156 ms
79,164 KB
testcase_19 AC 182 ms
81,984 KB
testcase_20 AC 160 ms
80,524 KB
testcase_21 AC 176 ms
92,912 KB
testcase_22 AC 203 ms
99,432 KB
testcase_23 AC 141 ms
77,584 KB
testcase_24 AC 142 ms
77,632 KB
testcase_25 AC 142 ms
77,460 KB
testcase_26 AC 140 ms
77,776 KB
testcase_27 AC 143 ms
77,624 KB
testcase_28 AC 142 ms
77,632 KB
testcase_29 AC 143 ms
77,464 KB
testcase_30 AC 145 ms
77,640 KB
testcase_31 AC 142 ms
77,692 KB
testcase_32 AC 139 ms
77,612 KB
testcase_33 AC 186 ms
98,672 KB
testcase_34 AC 187 ms
98,836 KB
testcase_35 AC 187 ms
98,772 KB
testcase_36 AC 192 ms
98,672 KB
testcase_37 AC 200 ms
98,800 KB
testcase_38 AC 195 ms
98,912 KB
testcase_39 AC 191 ms
98,704 KB
testcase_40 AC 209 ms
99,052 KB
testcase_41 AC 190 ms
98,524 KB
testcase_42 AC 186 ms
98,692 KB
testcase_43 AC 151 ms
98,744 KB
testcase_44 AC 157 ms
98,784 KB
testcase_45 AC 160 ms
98,548 KB
testcase_46 AC 159 ms
98,828 KB
testcase_47 AC 167 ms
98,696 KB
testcase_48 AC 165 ms
98,880 KB
testcase_49 AC 207 ms
98,672 KB
testcase_50 AC 213 ms
98,664 KB
testcase_51 AC 212 ms
98,772 KB
testcase_52 AC 204 ms
98,760 KB
testcase_53 AC 202 ms
98,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class SegTree(object):
    def __init__(self, N, op_data, u_data):
        self._n = N
        self.log = (N-1).bit_length()
        self.size = 1 << self.log

        self.op = op_data
        self.e = u_data

        self.data = [u_data] * (2 * self.size)
        # self.len = [1] * (2 * self.size)

    def __repr__(self):
        res = [self.get(i) for i in range(self._n)]
        return " ".join(map(str, res))

    def _update(self, i):
        self.data[i] = self.op(self.data[i << 1], self.data[i << 1 | 1])

    def initialize(self, arr=None):
        """ segtreeをarrで初期化する。len(arr) == Nにすること """
        if arr:
            for i, a in enumerate(arr, self.size):
                self.data[i] = a
        for i in reversed(range(1, self.size)):
            self._update(i)
            # self.len[i] = self.len[i << 1] + self.len[i << 1 | 1]

    def update(self, p, x):
        """ data[p] = x とする (0-indexed)"""
        p += self.size
        self.data[p] += x
        for i in range(1, self.log + 1):
            self._update(p >> i)

    def get(self, p):
        """ data[p]を返す """
        return self.data[p + self.size]

    def prod(self, l, r):
        """
        op_data(data[l], data[l+1], ..., data[r-1])を返す (0-indexed)
        """
        sml = self.e
        smr = self.e
        l += self.size
        r += self.size

        while l < r:
            if l & 1:
                sml = self.op(sml, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                smr = self.op(self.data[r], smr)
            l >>= 1
            r >>= 1
        return self.op(sml, smr)

    def all_prod(self):
        """ op(data[0], data[1], ... data[N-1])を返す """
        return self.data[1]

    def max_right(self, l, func):
        """
        func(l, l+1, ..., r-1) = True,
        func(l, l+1, ..., r-1, r) = Falseとなる r を返す
        """
        if l == self._n:
            return self._n
        l += self.size
        sm = self.e
        while True:
            while l % 2 == 0:
                l >>= 1
            if not func(self.op(sm, self.data[l])):
                while l < self.size:
                    l <<= 1
                    if func(self.op(sm, self.data[l])):
                        sm = self.op(sm, self.data[l])
                        l += 1
                return l - self.size
            sm = self.op(sm, self.data[l])
            l += 1
            if (l & -l) == l:
                break
        return self._n

    def min_left(self, r, func):
        """
        func(     l, l+1, ..., r-1) = True,
        func(l-1, l, l+1, ..., r-1) = Falseとなる l を返す
        """
        if r == 0:
            return 0
        r += self.size
        sm = self.e
        while True:
            r -= 1
            while r > 1 and r & 1:
                r >>= 1
            if not func(self.op(self.data[r], sm)):
                while r < self.size:
                    r = r << 1 | 1
                    if func(self.op(self.data[r], sm)):
                        sm = self.op(self.data[r], sm)
                        r -= 1
                return r + 1 - self.size
            sm = self.op(self.data[r], sm)
            if (r & -r) == r:
                break
        return 0


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

seg = SegTree(M, max, 0)
seg.initialize([a * M + i for i, a in enumerate(A)])
Q = int(input())
ans = []
for _ in range(Q):
    t, x, y = map(int, input().split())
    x -= 1
    y *= M
    if t == 1:
        seg.update(x, y)
    elif t == 2:
        seg.update(x, -y)
    else:
        ans.append(1 + seg.all_prod() % M)

print(*ans, sep="\n")
0