結果

問題 No.1705 Mode of long array
ユーザー tassei903tassei903
提出日時 2021-10-08 23:26:13
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 246 ms / 3,000 ms
コード長 1,985 bytes
コンパイル時間 1,384 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 95,512 KB
最終ジャッジ日時 2023-09-30 13:26:37
合計ジャッジ時間 14,364 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,224 KB
testcase_01 AC 68 ms
71,336 KB
testcase_02 AC 68 ms
71,436 KB
testcase_03 AC 106 ms
78,372 KB
testcase_04 AC 104 ms
77,872 KB
testcase_05 AC 107 ms
78,196 KB
testcase_06 AC 124 ms
78,140 KB
testcase_07 AC 136 ms
79,080 KB
testcase_08 AC 137 ms
78,920 KB
testcase_09 AC 129 ms
78,660 KB
testcase_10 AC 135 ms
79,192 KB
testcase_11 AC 141 ms
78,512 KB
testcase_12 AC 127 ms
78,644 KB
testcase_13 AC 232 ms
91,956 KB
testcase_14 AC 201 ms
85,292 KB
testcase_15 AC 191 ms
78,956 KB
testcase_16 AC 206 ms
79,636 KB
testcase_17 AC 186 ms
78,876 KB
testcase_18 AC 176 ms
78,972 KB
testcase_19 AC 217 ms
81,684 KB
testcase_20 AC 193 ms
80,416 KB
testcase_21 AC 211 ms
90,212 KB
testcase_22 AC 246 ms
95,060 KB
testcase_23 AC 166 ms
77,708 KB
testcase_24 AC 167 ms
78,288 KB
testcase_25 AC 166 ms
78,128 KB
testcase_26 AC 165 ms
77,916 KB
testcase_27 AC 169 ms
77,752 KB
testcase_28 AC 176 ms
77,780 KB
testcase_29 AC 173 ms
77,840 KB
testcase_30 AC 173 ms
77,972 KB
testcase_31 AC 169 ms
77,692 KB
testcase_32 AC 171 ms
77,896 KB
testcase_33 AC 226 ms
95,128 KB
testcase_34 AC 225 ms
95,292 KB
testcase_35 AC 226 ms
95,280 KB
testcase_36 AC 222 ms
95,168 KB
testcase_37 AC 221 ms
95,204 KB
testcase_38 AC 222 ms
95,184 KB
testcase_39 AC 219 ms
95,280 KB
testcase_40 AC 224 ms
95,156 KB
testcase_41 AC 226 ms
95,328 KB
testcase_42 AC 226 ms
95,312 KB
testcase_43 AC 203 ms
95,424 KB
testcase_44 AC 208 ms
95,404 KB
testcase_45 AC 203 ms
95,492 KB
testcase_46 AC 203 ms
95,452 KB
testcase_47 AC 230 ms
95,512 KB
testcase_48 AC 230 ms
95,352 KB
testcase_49 AC 240 ms
95,476 KB
testcase_50 AC 234 ms
95,396 KB
testcase_51 AC 232 ms
95,508 KB
testcase_52 AC 234 ms
95,380 KB
testcase_53 AC 228 ms
95,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
sys.setrecursionlimit(10**7)
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x,y : max(x,y), default=0):
        self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする
        self.default = default
        self.dat = [default]*(self.size*2) # 要素を単位元で初期化
        self.f = f

    def update(self, i, x):
        i += self.size
        self.dat[i] += x
        while i > 0:
            i >>= 1
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res

    def query2(self):
        s = 1
        #print(self.size)
        while s<self.size:
            #print(s)
            if self.dat[s*2]>self.dat[s*2+1]:
                s = s*2
            else:
                s = s*2+1
        return s-self.size


n,m= na()
a = na()
q = ni()
st = SegmentTree(m)
for i in range(m):
    st.update(i, a[i])

for i in range(q):
    t,x,y = na()
    if t==1:
        st.update(x-1, y)
    elif t==2:
        st.update(x-1,-y)
    else:
        print(st.query2()+1)
0