結果

問題 No.865 24時間降水量
ユーザー roarisroaris
提出日時 2019-08-16 22:35:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,227 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 81,796 KB
実行使用メモリ 104,280 KB
最終ジャッジ日時 2023-10-24 01:50:18
合計ジャッジ時間 11,981 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 39 ms
53,488 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 37 ms
53,500 KB
testcase_19 AC 38 ms
53,500 KB
testcase_20 AC 38 ms
53,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = []

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

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