結果

問題 No.1705 Mode of long array
ユーザー 👑 rin204rin204
提出日時 2022-01-23 01:18:50
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,967 bytes
コンパイル時間 566 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 100,048 KB
最終ジャッジ日時 2023-08-18 23:48:47
合計ジャッジ時間 15,528 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,136 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree():
    def __init__(self, n, e, ope, lst=[]):
        self.N0 = 2 ** (n - 1).bit_length()
        self.e = e
        self.ope = ope
        self.data = [e] * (2 * self.N0)
        if lst:
            for i in range(n):
                self.data[self.N0 + i] = lst[i]
            for i in range(self.N0 - 1, 0, -1):
                self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def f5(self):
        for i in range(self.N0 - 1, 0, -1):
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
                
    def update(self, i, x): #a_iの値をxに更新
        i += self.N0
        self.data[i] = (self.data[i][0] + x, self.data[i][1])
        while i > 1:
            i >>= 1
            self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1])
    
    def add(self, i, x):
        self.update(i, x + self.get(i))
    
    def query(self, l, r): #区間[l, r)での演算結果
        if r <= l:
            return self.e
            
        res = self.e
        l += self.N0
        r += self.N0
        while l < r:
            if l & 1:
                res = self.ope(res, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                res = self.ope(res, self.data[r])
            l >>= 1
            r >>= 1
        return res
            
    
    def get(self, i): #a_iの値を返す
        return self.data[self.N0 + i][0]

e = (-1, -1)
def ope(x, y):
    if x[0] > y[0]:
        return x
    elif x[0] < y[0]:
        return y
    elif x[1] > y[1]:
        return x
    else:
        return y

n, m = map(int, input().split())
A = list(map(int, input().split()))
seg = SegTree(n, e, ope, [(a, i) for i, a in enumerate(A, 1)])
q = int(input())
for _ in range(q):
    t, x, y = map(int, input().split())
    x -= 1
    if t == 1:
        seg.add(x, y)
    elif t == 2:
        seg.add(x, -y)
    else:
        print(seg.query(0, n)[1])
        
0