結果

問題 No.844 split game
ユーザー roarisroaris
提出日時 2019-12-25 15:54:50
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,440 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 90,456 KB
最終ジャッジ日時 2023-10-25 08:22:35
合計ジャッジ時間 10,859 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 173 ms
82,432 KB
testcase_01 AC 148 ms
82,256 KB
testcase_02 AC 311 ms
88,172 KB
testcase_03 AC 229 ms
86,000 KB
testcase_04 AC 153 ms
81,704 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 335 ms
90,432 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 339 ms
90,432 KB
testcase_19 AC 362 ms
90,456 KB
testcase_20 AC 359 ms
90,432 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 67 ms
70,836 KB
testcase_27 WA -
testcase_28 AC 55 ms
66,120 KB
testcase_29 AC 91 ms
77,188 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 62 ms
68,760 KB
testcase_33 AC 93 ms
77,336 KB
testcase_34 AC 85 ms
76,856 KB
testcase_35 AC 105 ms
77,700 KB
testcase_36 AC 89 ms
77,244 KB
testcase_37 AC 114 ms
78,492 KB
testcase_38 AC 121 ms
81,248 KB
testcase_39 AC 170 ms
86,304 KB
testcase_40 AC 103 ms
79,924 KB
testcase_41 AC 38 ms
53,540 KB
testcase_42 AC 38 ms
53,540 KB
testcase_43 AC 37 ms
53,540 KB
testcase_44 AC 38 ms
53,540 KB
testcase_45 AC 38 ms
53,540 KB
testcase_46 AC 40 ms
53,540 KB
testcase_47 AC 38 ms
53,540 KB
testcase_48 WA -
testcase_49 AC 39 ms
53,540 KB
testcase_50 AC 38 ms
53,540 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 39 ms
53,540 KB
testcase_54 AC 38 ms
53,540 KB
testcase_55 AC 39 ms
53,540 KB
testcase_56 AC 39 ms
53,540 KB
testcase_57 AC 38 ms
53,540 KB
testcase_58 AC 38 ms
53,540 KB
testcase_59 AC 39 ms
53,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class SegmentTree:
    def __init__(self, N, func, ele):
        n_ = 1
        
        while n_<N:
            n_ *= 2
            
        self.n = n_
        self.func = func
        self.ele = ele
        self.arr = [self.ele]*(2*self.n-1)
    
    def update(self, k, a):
        k += self.n-1
        self.arr[k] = a
        
        while k>0:
            k = (k-1)//2
            self.arr[k] = self.func(self.arr[2*k+1], self.arr[2*k+2])
        
    def query(self, l, r):
        L, R = l+self.n, r+self.n
        res = self.ele
        
        while L<R:
            if R&1:
                R -= 1
                res = self.func(res, self.arr[R-1])
            
            if L&1:
                res = self.func(res, self.arr[L-1])
                L += 1
            
            L >>= 1
            R >>= 1
            
        return res

N, M, A = map(int, input().split())
lrp = [tuple(map(int, input().split())) for _ in range(M)]
lrp.sort(key=lambda k: k[0])
dp = [-10**18]*N
st = SegmentTree(N, max, -10**18)

ans = 0

for li, ri, pi in lrp:
    li -= 1
    ri -= 1
    
    if li==0:
        dp[ri] = max(dp[ri], pi-A)
    else:
        dp[ri] = max(dp[ri], pi-2*A)
        dp[ri] = max(dp[ri], st.query(0, li)+pi-2*A)
        dp[ri] = max(dp[ri], dp[li-1]+pi-A)
    
    if ri==N-1:
        ans = max(ans, dp[ri]+A)
    else:
        ans = max(ans, dp[ri])
        
print(ans)
0