結果

問題 No.631 Noelちゃんと電車旅行
ユーザー mkawa2mkawa2
提出日時 2020-07-09 11:44:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,989 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 95,360 KB
最終ジャッジ日時 2024-04-16 03:39:37
合計ジャッジ時間 7,797 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class LazySeg:
    def __init__(self, aa):
        inf = 10 ** 16
        n = 1 << (len(aa) - 1).bit_length()
        tree = [-inf] * (2 * n)
        lazy = [0] * (2 * n)
        tree[n:n + len(aa)] = aa
        for u in range(n - 1, 0, -1): tree[u] = max(tree[u * 2], tree[u * 2 + 1])
        self.tree = tree
        self.lazy = lazy
        self.n = n
        self.inf = inf

    def add(self, l, r, a, u=1, tl=0, tr=-1):
        if tr == -1: tr = self.n
        if r <= tl or tr <= l: return
        if l <= tl and tr <= r:
            self.lazy[u] += a
            return
        tm = (tl + tr) // 2
        self.add(l, r, a, u * 2, tl, tm)
        self.add(l, r, a, u * 2 + 1, tm, tr)

    def max(self, l, r, u=1, tl=0, tr=-1):
        if tr == -1: tr = self.n
        if r <= tl or tr <= l: return -self.inf
        if l <= tl and tr <= r:
            self._eval(u)
            return self.tree[u]
        self.lazy[u*2]+=self.lazy[u]
        self.lazy[u*2+1]+=self.lazy[u]
        self.lazy[u]=0
        tm = (tl + tr) // 2
        return max(self.max(l, r, u * 2, tl, tm),self.max(l, r, u * 2 + 1, tm, tr))

    def _eval(self, u):
        if u>=self.n:
            self.tree[u]+=self.lazy[u]
            self.lazy[u]=0
            return
        self.lazy[u*2]+=self.lazy[u]
        self.lazy[u*2+1]+=self.lazy[u]
        self.lazy[u]=0
        self._eval(u*2)
        self._eval(u*2+1)
        self.tree[u]=max(self.tree[u*2],self.tree[u*2+1])

n=II()
tt=LI()
for i in range(n-1):tt[i]-=i*3
st=LazySeg(tt)
mn=3*(n-1)
for _ in range(II()):
    l,r,d=MI()
    st.add(l-1,r,d)
    print(mn+st.max(0,n-1))
0