結果

問題 No.1705 Mode of long array
ユーザー 👑 rin204rin204
提出日時 2022-01-23 01:22:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 424 ms / 3,000 ms
コード長 1,954 bytes
コンパイル時間 1,071 ms
コンパイル使用メモリ 86,856 KB
実行使用メモリ 102,352 KB
最終ジャッジ日時 2023-08-18 23:57:54
合計ジャッジ時間 20,738 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,064 KB
testcase_01 AC 71 ms
71,180 KB
testcase_02 AC 70 ms
71,340 KB
testcase_03 AC 152 ms
77,776 KB
testcase_04 AC 129 ms
77,612 KB
testcase_05 AC 151 ms
78,040 KB
testcase_06 AC 206 ms
79,052 KB
testcase_07 AC 209 ms
79,404 KB
testcase_08 AC 213 ms
79,096 KB
testcase_09 AC 208 ms
78,952 KB
testcase_10 AC 204 ms
79,288 KB
testcase_11 AC 209 ms
79,708 KB
testcase_12 AC 205 ms
78,720 KB
testcase_13 AC 376 ms
97,532 KB
testcase_14 AC 333 ms
88,024 KB
testcase_15 AC 332 ms
80,524 KB
testcase_16 AC 360 ms
81,656 KB
testcase_17 AC 307 ms
80,300 KB
testcase_18 AC 280 ms
81,020 KB
testcase_19 AC 369 ms
83,864 KB
testcase_20 AC 312 ms
82,212 KB
testcase_21 AC 331 ms
95,176 KB
testcase_22 AC 395 ms
102,352 KB
testcase_23 AC 241 ms
80,012 KB
testcase_24 AC 240 ms
79,836 KB
testcase_25 AC 239 ms
79,680 KB
testcase_26 AC 236 ms
79,804 KB
testcase_27 AC 226 ms
79,572 KB
testcase_28 AC 238 ms
79,964 KB
testcase_29 AC 236 ms
79,568 KB
testcase_30 AC 237 ms
79,836 KB
testcase_31 AC 235 ms
79,528 KB
testcase_32 AC 242 ms
79,828 KB
testcase_33 AC 314 ms
97,936 KB
testcase_34 AC 328 ms
97,772 KB
testcase_35 AC 326 ms
97,776 KB
testcase_36 AC 324 ms
97,888 KB
testcase_37 AC 325 ms
97,732 KB
testcase_38 AC 318 ms
98,016 KB
testcase_39 AC 309 ms
97,884 KB
testcase_40 AC 320 ms
97,864 KB
testcase_41 AC 314 ms
97,884 KB
testcase_42 AC 311 ms
97,700 KB
testcase_43 AC 381 ms
97,772 KB
testcase_44 AC 408 ms
97,676 KB
testcase_45 AC 398 ms
97,792 KB
testcase_46 AC 393 ms
97,760 KB
testcase_47 AC 422 ms
97,840 KB
testcase_48 AC 424 ms
97,716 KB
testcase_49 AC 383 ms
97,928 KB
testcase_50 AC 414 ms
97,672 KB
testcase_51 AC 398 ms
97,856 KB
testcase_52 AC 393 ms
97,856 KB
testcase_53 AC 367 ms
97,716 KB
権限があれば一括ダウンロードができます

ソースコード

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] = (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(m, 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, m)[1])
    
        
0