結果

問題 No.631 Noelちゃんと電車旅行
ユーザー H3PO4H3PO4
提出日時 2020-10-16 14:04:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,260 ms / 2,000 ms
コード長 2,459 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 86,484 KB
実行使用メモリ 96,332 KB
最終ジャッジ日時 2023-09-28 01:55:45
合計ジャッジ時間 20,546 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 882 ms
81,552 KB
testcase_01 AC 1,259 ms
94,000 KB
testcase_02 AC 1,260 ms
95,172 KB
testcase_03 AC 1,240 ms
96,332 KB
testcase_04 AC 1,181 ms
93,436 KB
testcase_05 AC 1,222 ms
94,984 KB
testcase_06 AC 614 ms
84,612 KB
testcase_07 AC 467 ms
85,460 KB
testcase_08 AC 1,009 ms
93,256 KB
testcase_09 AC 1,086 ms
86,820 KB
testcase_10 AC 828 ms
89,980 KB
testcase_11 AC 749 ms
86,044 KB
testcase_12 AC 897 ms
91,400 KB
testcase_13 AC 864 ms
83,068 KB
testcase_14 AC 494 ms
80,788 KB
testcase_15 AC 771 ms
84,016 KB
testcase_16 AC 89 ms
76,044 KB
testcase_17 AC 86 ms
75,732 KB
testcase_18 AC 88 ms
76,088 KB
testcase_19 AC 87 ms
75,904 KB
testcase_20 AC 86 ms
75,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class LazySegTree:
    """
    https://tjkendev.github.io/procon-library/python/range_query/rmq_raq_segment_tree_lp.html より拝借し、一部改変しています。
    """
    def __init__(self, N):
        # N: 処理する区間の長さ
        self.N = N
        self.LV = (self.N - 1).bit_length()
        self.N0 = 2 ** self.LV
        self.data = [0] * (2 * self.N0)
        self.lazy = [0] * (2 * self.N0)

    def gindex(self, l, r):
        L = (l + self.N0) >> 1
        R = (r + self.N0) >> 1
        lc = 0 if l & 1 else (L & -L).bit_length()
        rc = 0 if r & 1 else (R & -R).bit_length()
        for i in range(self.LV):
            if rc <= i:
                yield R
            if L < R and lc <= i:
                yield L
            L >>= 1
            R >>= 1

    # 遅延伝搬処理
    def propagates(self, *ids):
        for i in reversed(ids):
            v = self.lazy[i - 1]
            if not v:
                continue
            self.lazy[2 * i - 1] += v
            self.lazy[2 * i] += v
            self.data[2 * i - 1] += v
            self.data[2 * i] += v
            self.lazy[i - 1] = 0

    # 区間[l, r)にxを加算
    def update(self, l, r, x):
        *ids, = self.gindex(l, r)
        self.propagates(*ids)

        L = self.N0 + l
        R = self.N0 + r
        while L < R:
            if R & 1:
                R -= 1
                self.lazy[R - 1] += x
                self.data[R - 1] += x
            if L & 1:
                self.lazy[L - 1] += x
                self.data[L - 1] += x
                L += 1
            L >>= 1
            R >>= 1
        for i in ids:
            self.data[i - 1] = max(self.data[2 * i - 1], self.data[2 * i])

    # 区間[l, r)内の最大値を求める
    def query(self, l, r):
        self.propagates(*self.gindex(l, r))
        L = self.N0 + l
        R = self.N0 + r

        s = 0
        while L < R:
            if R & 1:
                R -= 1
                s = max(s, self.data[R - 1])
            if L & 1:
                s = max(s, self.data[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return s


N = int(input())
S = LazySegTree(N)
req_time = 3
T = map(int, input().split())
for i, t in enumerate(T):
    S.update(i + 1, i + 2, t - req_time * i)
M = int(input())
for _ in range(M):
    l, r, d = map(int, input().split())
    S.update(l, r + 1, d)
    print(S.query(1, N + 1) + req_time * (N - 1))
0