結果

問題 No.865 24時間降水量
ユーザー nadarenadare
提出日時 2019-08-17 15:17:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,384 ms / 2,000 ms
コード長 3,482 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 118,504 KB
最終ジャッジ日時 2024-09-24 19:48:37
合計ジャッジ時間 7,658 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,780 KB
testcase_01 AC 40 ms
54,436 KB
testcase_02 AC 40 ms
54,076 KB
testcase_03 AC 40 ms
53,700 KB
testcase_04 AC 45 ms
54,168 KB
testcase_05 AC 157 ms
77,564 KB
testcase_06 AC 158 ms
77,572 KB
testcase_07 AC 158 ms
77,568 KB
testcase_08 AC 159 ms
77,316 KB
testcase_09 AC 147 ms
77,632 KB
testcase_10 AC 218 ms
78,872 KB
testcase_11 AC 218 ms
78,472 KB
testcase_12 AC 214 ms
78,360 KB
testcase_13 AC 216 ms
78,556 KB
testcase_14 AC 215 ms
78,576 KB
testcase_15 AC 1,353 ms
118,504 KB
testcase_16 AC 1,384 ms
118,500 KB
testcase_17 AC 1,289 ms
118,328 KB
testcase_18 AC 38 ms
53,348 KB
testcase_19 AC 40 ms
55,608 KB
testcase_20 AC 39 ms
53,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
from math import sqrt
import sys
input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

class SegmentTree:
    
    def __init__(self, N, init_node=None):
        self.size = 2**int.bit_length(N)
        self.node = [0]*(2*self.size-1)
        if not init_node is None:
            for i in range(N):
                self.node[i+self.size-1] = init_node[i]
        for i in range(self.size-2, -1, -1):
            self.node[i] = max(self.node[2*i+1], self.node[2*i+2])

    def add(self, x, val):
        x += self.size - 1
        self.node[x] += val
        while x:
            x = (x-1)//2
            self.node[x] = max(self.node[2*x+1], self.node[2*x+2])

class LazySegmentTree:
    
    def __init__(self, N, init_node=None, mode="max"):
        if mode == "sum":
            self.aggfunc = lambda x, y: x+y
            self.lazyaddfunc = lambda x, l, r: x*(r-l)
            self.lazyfunc = lambda x: x//2
        
        elif mode == "max":
            self.aggfunc = lambda x, y: x if x > y else y
            self.lazyaddfunc = lambda x, l, r: x
            self.lazyfunc = lambda x: x
        
        self.size = 2**int.bit_length(N)
        self.node = [0]*(2*self.size-1)
        if not init_node is None:
            for i in range(N):
                self.node[i+self.size-1] = init_node[i]
            for i in range(self.size-2, -1, -1):
                self.node[i] = self.aggfunc(self.node[2*i+1], self.node[2*i+2])
        self.lazy = [0]*(2*self.size-1)

    def eval(self, k, l, r):
        if self.lazy[k]:
            self.node[k] += self.lazy[k]
            if r-l-1:
                self.lazy[2*k+1] += self.lazyfunc(self.lazy[k])
                self.lazy[2*k+2] += self.lazyfunc(self.lazy[k])
            self.lazy[k] = 0

    def add(self, a, b, val):
        Q = [[0, 0, self.size]]
        Q2 = []

        def inner(k, l, r):
            nonlocal Q, Q2
            self.eval(k, l, r)
            if (b <= l) or (r <= a):
                return
            if (a<=l) and (r<=b):
                self.lazy[k] += self.lazyaddfunc(val, l, r)
                self.eval(k, l, r)
            else:
                Q.append([2*k+1, l, (l+r)//2])
                Q.append([2*k+2, (l+r)//2, r])
                Q2.append(k)

        while Q:
            inner(*Q.pop())
        
        while Q2:
            k = Q2.pop()
            self.node[k] = self.aggfunc(self.node[2*k+1], self.node[2*k+2])


    def getagg(self, a, b):
        ix = 0
        Q = [[0, 0, self.size, 0]]
        Q2 = []
        S = [0]

        def inner(k, l, r, i):
            nonlocal ix, Q, Q2, S
            if (a<=l) and (r<=b):
                S[i] = self.node[k]
            else:
                Q.append([2*k+1, l, (l+r)//2, ix+1])
                Q.append([2*k+2, (l+r)//2, r, ix+2])
                Q2.append([ix, ix+1, ix+2])
                S.extend([0, 0])
                ix += 2
        while Q:
            inner(*Q.pop())
        while Q2:
            x, y, z = Q2.pop()
            S[x] = self.aggfunc(S[y], S[z])
        return S[0]
        

 
N = int(input())
A = [0] * 23 + inpl() + [0]*23

s = sum(A[:24])
X = [0]*(N + 46)
for i in range(24):
    X[i] = A[23]*1


s = A[23]*1
for i in range(24, N+46):
    s += A[i] - A[i-24]
    X[i] = s


seg = LazySegmentTree(len(X), X)
for _ in range(int(input())):
    t, v = inpl()
    t += 22
    d = v - A[t]
    A[t] = v
    seg.add(t, t+24, d)
    print(seg.node[0])
0