結果

問題 No.865 24時間降水量
ユーザー roarisroaris
提出日時 2019-08-16 22:52:59
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,295 bytes
コンパイル時間 1,089 ms
コンパイル使用メモリ 81,520 KB
実行使用メモリ 121,404 KB
最終ジャッジ日時 2023-10-24 03:10:12
合計ジャッジ時間 9,995 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,444 KB
testcase_01 AC 38 ms
53,444 KB
testcase_02 AC 38 ms
53,444 KB
testcase_03 AC 39 ms
53,444 KB
testcase_04 AC 38 ms
53,444 KB
testcase_05 AC 112 ms
76,372 KB
testcase_06 AC 112 ms
76,792 KB
testcase_07 AC 112 ms
76,744 KB
testcase_08 AC 114 ms
77,032 KB
testcase_09 AC 101 ms
76,320 KB
testcase_10 AC 187 ms
77,084 KB
testcase_11 AC 188 ms
77,376 KB
testcase_12 AC 190 ms
77,024 KB
testcase_13 AC 206 ms
77,716 KB
testcase_14 AC 191 ms
77,316 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 38 ms
53,444 KB
testcase_19 AC 37 ms
53,444 KB
testcase_20 AC 38 ms
53,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class SegmentTree:
    def __init__(self, N):
        n_ = 1
        while n_ < N:
            n_ *= 2
        self.n = n_
        self.arr = [-10 ** 18] * (2*self.n - 1)
    
    def update(self, k, a):
        k += self.n - 1
        self.arr[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.arr[k] = max(self.arr[2*k + 1], self.arr[2*k + 2])
        
    def query_sub(self, a, b, k, l, r):
        if r <= a or b <= l:
            return -10 ** 18
        
        if a <= l and r <= b:
            return self.arr[k]
        else:
            vl = self.query_sub(a, b, 2*k + 1, l, (l+r) / 2)
            vr = self.query_sub(a, b, 2*k + 2, (l+r) / 2, r)
            return max(vl, vr)
    
    def query(self, a, b):
        return self.query_sub(a, b, 0, 0, self.n)

N = int(input())
A = list(map(int, input().split()))
B = [sum(A[0:24])]

for i in range(1, N-23):
    B.append(B[-1] + A[i+23] - A[i-1])

M = len(B)
st = SegmentTree(M)

for i in range(M):
    st.update(i, B[i])

Q = int(input())

for _ in range(Q):
    Ti, Vi = map(int, input().split())
    Ti -= 1
    for i in range(max(Ti-23, 0), min(Ti+1, M)):
        st.update(i, B[i]-A[Ti]+Vi)
        B[i] = B[i] - A[Ti] + Vi
    A[Ti] = Vi
    print(st.query(0, M))
0