結果

問題 No.865 24時間降水量
ユーザー roarisroaris
提出日時 2019-08-16 23:21:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,844 ms / 2,000 ms
コード長 1,095 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 81,260 KB
実行使用メモリ 121,320 KB
最終ジャッジ日時 2023-10-24 05:25:34
合計ジャッジ時間 9,702 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,300 KB
testcase_01 AC 38 ms
53,300 KB
testcase_02 AC 36 ms
53,300 KB
testcase_03 AC 36 ms
53,300 KB
testcase_04 AC 36 ms
53,300 KB
testcase_05 AC 104 ms
76,364 KB
testcase_06 AC 105 ms
76,628 KB
testcase_07 AC 116 ms
76,628 KB
testcase_08 AC 108 ms
76,624 KB
testcase_09 AC 96 ms
76,340 KB
testcase_10 AC 170 ms
77,096 KB
testcase_11 AC 176 ms
77,244 KB
testcase_12 AC 259 ms
78,036 KB
testcase_13 AC 183 ms
76,944 KB
testcase_14 AC 169 ms
77,196 KB
testcase_15 AC 1,722 ms
121,320 KB
testcase_16 AC 1,814 ms
121,320 KB
testcase_17 AC 1,844 ms
121,320 KB
testcase_18 AC 37 ms
53,304 KB
testcase_19 AC 36 ms
53,304 KB
testcase_20 AC 36 ms
53,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def init(NN):
    n_ = 1
    while n_ < NN:
        n_ *= 2
    n = n_
    arr = [-10 ** 18] * (2*n - 1)
    return n, arr

def update(k, a):
    k += n - 1
    arr[k] = a
    while k > 0:
        k = (k - 1) // 2
        arr[k] = max(arr[2*k + 1], arr[2*k + 2])
        
def query_sub(a, b, k, l, r):
    if r <= a or b <= l:
        return -10 ** 18
        
    if a <= l and r <= b:
        return arr[k]
    else:
        vl = query_sub(a, b, 2*k + 1, l, (l+r) / 2)
        vr = query_sub(a, b, 2*k + 2, (l+r) / 2, r)
        return max(vl, vr)
    
def query(a, b):
    return query_sub(a, b, 0, 0, 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)
n, arr = init(M)

for i in range(M):
    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)):
        update(i, B[i]-A[Ti]+Vi)
        B[i] = B[i] - A[Ti] + Vi
    A[Ti] = Vi
    print(query(0, M))
0