結果

問題 No.777 再帰的ケーキ
ユーザー convexineqconvexineq
提出日時 2021-05-21 18:02:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 882 ms / 2,000 ms
コード長 1,703 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,252 KB
実行使用メモリ 158,740 KB
最終ジャッジ日時 2024-04-18 14:18:03
合計ジャッジ時間 9,261 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,752 KB
testcase_01 AC 41 ms
52,628 KB
testcase_02 AC 40 ms
54,400 KB
testcase_03 AC 39 ms
53,552 KB
testcase_04 AC 39 ms
52,432 KB
testcase_05 AC 39 ms
53,612 KB
testcase_06 AC 39 ms
53,032 KB
testcase_07 AC 39 ms
52,532 KB
testcase_08 AC 39 ms
52,392 KB
testcase_09 AC 39 ms
52,500 KB
testcase_10 AC 40 ms
53,684 KB
testcase_11 AC 38 ms
53,416 KB
testcase_12 AC 39 ms
53,012 KB
testcase_13 AC 36 ms
52,800 KB
testcase_14 AC 39 ms
53,232 KB
testcase_15 AC 36 ms
52,616 KB
testcase_16 AC 38 ms
53,348 KB
testcase_17 AC 38 ms
52,344 KB
testcase_18 AC 39 ms
52,396 KB
testcase_19 AC 37 ms
53,536 KB
testcase_20 AC 37 ms
53,288 KB
testcase_21 AC 96 ms
76,880 KB
testcase_22 AC 98 ms
77,012 KB
testcase_23 AC 71 ms
72,276 KB
testcase_24 AC 68 ms
71,656 KB
testcase_25 AC 95 ms
76,724 KB
testcase_26 AC 96 ms
76,520 KB
testcase_27 AC 66 ms
72,628 KB
testcase_28 AC 811 ms
136,116 KB
testcase_29 AC 786 ms
136,184 KB
testcase_30 AC 855 ms
158,696 KB
testcase_31 AC 882 ms
158,740 KB
testcase_32 AC 398 ms
142,904 KB
testcase_33 AC 202 ms
84,004 KB
testcase_34 AC 206 ms
87,540 KB
testcase_35 AC 677 ms
125,216 KB
testcase_36 AC 373 ms
143,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class segment_tree:
    __slots__ = ["op_M", "e_M","N","N0","dat"]
    def __init__(self, N, operator_M, e_M):
        self.op_M = operator_M
        self.e_M = e_M
        self.N = N
        self.N0 = 1<<(N-1).bit_length()
        self.dat = [self.e_M]*(2*self.N0)
    
    # 長さNの配列 initial で初期化
    def build(self, initial):
        assert self.N == len(initial)
        self.dat[self.N0:self.N0+len(initial)] = initial[:]
        for k in range(self.N0-1,0,-1):
            self.dat[k] = self.op_M(self.dat[2*k], self.dat[2*k+1])

    # a_k の値を x に更新
    def update(self,k,x):
        k += self.N0
        self.dat[k] = x
        k >>= 1
        while k:
            self.dat[k] = self.op_M(self.dat[2*k], self.dat[2*k+1])
            k >>= 1

    # 区間[L,R]をopでまとめる
    def query(self,L,R):
        L += self.N0; R += self.N0 + 1 
        sl = sr = self.e_M
        while L < R:
            if R & 1:
                R -= 1
                sr = self.op_M(self.dat[R],sr)
            if L & 1:
                sl = self.op_M(sl,self.dat[L])
                L += 1
            L >>= 1; R >>= 1
        return self.op_M(sl,sr)

    def get(self, k): #k番目の値を取得。query[k,k]と同じ
        return self.dat[k+self.N0]

n = int(input())
abc = []
M = 1<<30
s = set()
for _ in range(n):
    a,b,c = map(int,input().split())
    s.add(b)
    abc.append((a*M+(M-b),c))
abc.sort(key=lambda x:x[0])
sb = sorted(s)
zb = {bi:i for i,bi in enumerate(sb)}
L = len(sb)
B = segment_tree(L,max,0)
res = [0]*L
for ab,c in abc:
    a,b = divmod(ab,M)
    b = M-b
    i = zb[b]
    v = B.query(0,i-1)+c
    if B.get(i) < v:
        B.update(i,v)
print(B.dat[1])
0