結果

問題 No.631 Noelちゃんと電車旅行
ユーザー mkawa2mkawa2
提出日時 2020-07-09 15:54:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,526 ms / 2,000 ms
コード長 1,838 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 95,312 KB
最終ジャッジ日時 2024-04-10 08:03:40
合計ジャッジ時間 19,514 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 951 ms
86,452 KB
testcase_01 AC 1,490 ms
95,100 KB
testcase_02 AC 1,363 ms
94,812 KB
testcase_03 AC 1,498 ms
95,068 KB
testcase_04 AC 1,526 ms
95,200 KB
testcase_05 AC 1,477 ms
95,312 KB
testcase_06 AC 633 ms
84,052 KB
testcase_07 AC 330 ms
85,452 KB
testcase_08 AC 1,171 ms
91,440 KB
testcase_09 AC 1,142 ms
89,492 KB
testcase_10 AC 785 ms
91,484 KB
testcase_11 AC 804 ms
86,964 KB
testcase_12 AC 1,032 ms
92,944 KB
testcase_13 AC 884 ms
85,752 KB
testcase_14 AC 443 ms
80,344 KB
testcase_15 AC 794 ms
84,768 KB
testcase_16 AC 52 ms
64,184 KB
testcase_17 AC 55 ms
66,208 KB
testcase_18 AC 51 ms
62,868 KB
testcase_19 AC 50 ms
63,084 KB
testcase_20 AC 51 ms
63,088 KB
権限があれば一括ダウンロードができます

ソースコード

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
        self._eval(u)
        if r <= tl or tr <= l: return
        if l <= tl and tr <= r:
            self.lazy[u] += a
            self._eval(u)
            return
        tm = (tl + tr) // 2
        self.add(l, r, a, u * 2, tl, tm)
        self.add(l, r, a, u * 2 + 1, tm, tr)
        self.tree[u]=max(self.tree[u*2],self.tree[u*2+1])

    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
        self._eval(u)
        if l <= tl and tr <= r:return self.tree[u]
        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):
        self.tree[u]+=self.lazy[u]
        if u<self.n:
            self.lazy[u * 2] += self.lazy[u]
            self.lazy[u * 2 + 1] += self.lazy[u]
        self.lazy[u]=0

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