結果

問題 No.865 24時間降水量
ユーザー rlangevinrlangevin
提出日時 2023-11-07 20:28:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,434 ms / 2,000 ms
コード長 1,331 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 81,860 KB
実行使用メモリ 107,916 KB
最終ジャッジ日時 2023-11-07 20:28:28
合計ジャッジ時間 7,565 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
59,556 KB
testcase_01 AC 35 ms
53,664 KB
testcase_02 AC 35 ms
53,664 KB
testcase_03 AC 36 ms
53,664 KB
testcase_04 AC 38 ms
59,556 KB
testcase_05 AC 88 ms
76,276 KB
testcase_06 AC 85 ms
76,400 KB
testcase_07 AC 86 ms
76,256 KB
testcase_08 AC 85 ms
76,420 KB
testcase_09 AC 89 ms
76,336 KB
testcase_10 AC 152 ms
77,208 KB
testcase_11 AC 146 ms
77,348 KB
testcase_12 AC 149 ms
77,356 KB
testcase_13 AC 149 ms
77,228 KB
testcase_14 AC 150 ms
77,212 KB
testcase_15 AC 1,434 ms
107,916 KB
testcase_16 AC 1,386 ms
107,916 KB
testcase_17 AC 1,407 ms
107,916 KB
testcase_18 AC 35 ms
53,664 KB
testcase_19 AC 37 ms
53,664 KB
testcase_20 AC 35 ms
53,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class SegmentTree:
    def __init__(self, size, f=min, default=10 ** 18):
        self.size = 2**(size-1).bit_length() 
        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


N = int(input())
A = list(map(int, input().split()))
Seg = SegmentTree(N, max, 0)
for i in range(N - 23):
    Seg.update(i, sum(A[i:i+24]))
    
Q = int(input())
for _ in range(Q):
    T, V = map(int, input().split())
    T -= 1
    A[T] = V
    ind = max(0, T - 23)
    val = sum(A[ind:ind+24])
    for i in range(ind, min(N - 23, T + 1)):
        Seg.update(i, val)
        val -= A[i]
        if i + 24 <= N - 1:
            val += A[i+24]
    print(Seg.query(0, N))
0