結果

問題 No.844 split game
ユーザー brthyyjpbrthyyjp
提出日時 2021-02-23 02:07:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 461 ms / 2,000 ms
コード長 2,024 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 93,992 KB
最終ジャッジ日時 2023-10-21 19:47:53
合計ジャッジ時間 16,439 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 283 ms
84,468 KB
testcase_01 AC 245 ms
87,696 KB
testcase_02 AC 318 ms
86,980 KB
testcase_03 AC 342 ms
88,916 KB
testcase_04 AC 269 ms
82,916 KB
testcase_05 AC 461 ms
92,872 KB
testcase_06 AC 260 ms
83,408 KB
testcase_07 AC 212 ms
85,000 KB
testcase_08 AC 200 ms
80,928 KB
testcase_09 AC 307 ms
83,572 KB
testcase_10 AC 448 ms
90,268 KB
testcase_11 AC 417 ms
92,432 KB
testcase_12 AC 313 ms
84,136 KB
testcase_13 AC 270 ms
81,572 KB
testcase_14 AC 309 ms
85,972 KB
testcase_15 AC 461 ms
93,880 KB
testcase_16 AC 428 ms
93,484 KB
testcase_17 AC 426 ms
93,992 KB
testcase_18 AC 423 ms
93,232 KB
testcase_19 AC 422 ms
93,500 KB
testcase_20 AC 434 ms
93,332 KB
testcase_21 AC 415 ms
92,892 KB
testcase_22 AC 457 ms
93,136 KB
testcase_23 AC 121 ms
77,372 KB
testcase_24 AC 168 ms
78,668 KB
testcase_25 AC 126 ms
76,852 KB
testcase_26 AC 105 ms
76,916 KB
testcase_27 AC 156 ms
76,956 KB
testcase_28 AC 101 ms
76,644 KB
testcase_29 AC 154 ms
78,088 KB
testcase_30 AC 176 ms
79,244 KB
testcase_31 AC 167 ms
78,392 KB
testcase_32 AC 90 ms
76,312 KB
testcase_33 AC 127 ms
77,140 KB
testcase_34 AC 116 ms
77,116 KB
testcase_35 AC 129 ms
77,204 KB
testcase_36 AC 120 ms
77,116 KB
testcase_37 AC 139 ms
77,392 KB
testcase_38 AC 215 ms
79,968 KB
testcase_39 AC 333 ms
83,908 KB
testcase_40 AC 232 ms
82,856 KB
testcase_41 AC 40 ms
53,456 KB
testcase_42 AC 39 ms
53,456 KB
testcase_43 AC 39 ms
53,456 KB
testcase_44 AC 39 ms
53,456 KB
testcase_45 AC 40 ms
53,456 KB
testcase_46 AC 40 ms
53,456 KB
testcase_47 AC 40 ms
53,456 KB
testcase_48 AC 40 ms
53,456 KB
testcase_49 AC 39 ms
53,456 KB
testcase_50 AC 40 ms
53,456 KB
testcase_51 AC 39 ms
53,456 KB
testcase_52 AC 38 ms
53,456 KB
testcase_53 AC 38 ms
53,456 KB
testcase_54 AC 38 ms
53,456 KB
testcase_55 AC 38 ms
53,456 KB
testcase_56 AC 38 ms
53,456 KB
testcase_57 AC 37 ms
53,456 KB
testcase_58 AC 38 ms
53,456 KB
testcase_59 AC 39 ms
53,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:
    def __init__(self, init_val, ide_ele, segfunc):
        self.n = len(init_val)
        self.num = 2**(self.n-1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.seg = [ide_ele]*2*self.num
        # set_val
        for i in range(self.n):
            self.seg[i+self.num] = init_val[i]
        # built
        for i in range(self.num-1, 0, -1):
            self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1])

    def update(self, k, x):
        k += self.num
        self.seg[k] = x
        while k:
            k = k >> 1
            self.seg[k] = self.segfunc(self.seg[2*k], self.seg[2*k+1])

    def query(self, l, r):
        if r <= l:
            return self.ide_ele
        l += self.num
        r += self.num
        lres = self.ide_ele
        rres = self.ide_ele
        while l < r:
            if r & 1:
                r -= 1
                rres = self.segfunc(self.seg[r], rres)
            if l & 1:
                lres = self.segfunc(lres, self.seg[l])
                l += 1
            l = l >> 1
            r = r >> 1
        res = self.segfunc(lres, rres)
        return res

    def __str__(self): # for debug
        arr = [self.query(i,i+1) for i in range(self.n)]
        return str(arr)

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

INF = 10**18

def main():
    n, m, a = map(int, input().split())
    L = [0]*n
    R = [[] for i in range(n)]
    for i in range(m):
        l, r, p = map(int, input().split())
        l, r = l-1, r-1
        R[r].append((l, p))

    seg = SegTree([-INF]*(n+2), -INF, max)
    seg.update(0, 0)
    for i in range(n):
        for l, p in R[i]:
            t = max(seg.query(0, l)-a, seg.query(l, l+1))
            if i != n-1:
                seg.update(i+1, max(seg.query(i+1, i+2), t+p-a))
            else:
                seg.update(i+1, max(seg.query(i+1, i+2), t+p))
    #print(seg)
    print(seg.query(0, n+1))

if __name__ == '__main__':
    main()
0