結果

問題 No.1014 competitive fighting
ユーザー mkawa2mkawa2
提出日時 2020-05-16 15:42:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,536 ms / 2,000 ms
コード長 3,075 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 81,820 KB
実行使用メモリ 106,704 KB
最終ジャッジ日時 2023-10-23 16:15:25
合計ジャッジ時間 40,373 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,568 KB
testcase_01 AC 38 ms
53,572 KB
testcase_02 AC 37 ms
53,572 KB
testcase_03 AC 39 ms
53,568 KB
testcase_04 AC 38 ms
53,572 KB
testcase_05 AC 1,524 ms
100,752 KB
testcase_06 AC 1,513 ms
100,888 KB
testcase_07 AC 1,428 ms
99,620 KB
testcase_08 AC 1,486 ms
100,456 KB
testcase_09 AC 1,477 ms
100,188 KB
testcase_10 AC 783 ms
106,704 KB
testcase_11 AC 314 ms
94,708 KB
testcase_12 AC 1,521 ms
99,868 KB
testcase_13 AC 767 ms
88,228 KB
testcase_14 AC 692 ms
86,592 KB
testcase_15 AC 857 ms
90,804 KB
testcase_16 AC 157 ms
78,812 KB
testcase_17 AC 386 ms
81,632 KB
testcase_18 AC 1,282 ms
96,636 KB
testcase_19 AC 1,412 ms
98,472 KB
testcase_20 AC 603 ms
85,496 KB
testcase_21 AC 1,170 ms
94,896 KB
testcase_22 AC 947 ms
90,812 KB
testcase_23 AC 472 ms
82,820 KB
testcase_24 AC 485 ms
82,980 KB
testcase_25 AC 228 ms
79,292 KB
testcase_26 AC 1,148 ms
94,444 KB
testcase_27 AC 388 ms
81,884 KB
testcase_28 AC 424 ms
82,280 KB
testcase_29 AC 112 ms
76,052 KB
testcase_30 AC 1,454 ms
99,436 KB
testcase_31 AC 1,117 ms
94,144 KB
testcase_32 AC 93 ms
75,880 KB
testcase_33 AC 100 ms
77,156 KB
testcase_34 AC 432 ms
91,652 KB
testcase_35 AC 590 ms
94,632 KB
testcase_36 AC 413 ms
89,636 KB
testcase_37 AC 99 ms
76,828 KB
testcase_38 AC 393 ms
87,564 KB
testcase_39 AC 245 ms
82,328 KB
testcase_40 AC 373 ms
87,352 KB
testcase_41 AC 268 ms
84,968 KB
testcase_42 AC 568 ms
93,988 KB
testcase_43 AC 98 ms
77,044 KB
testcase_44 AC 514 ms
92,336 KB
testcase_45 AC 354 ms
85,912 KB
testcase_46 AC 112 ms
77,904 KB
testcase_47 AC 213 ms
81,804 KB
testcase_48 AC 434 ms
90,396 KB
testcase_49 AC 89 ms
76,644 KB
testcase_50 AC 517 ms
92,740 KB
testcase_51 AC 322 ms
85,860 KB
testcase_52 AC 93 ms
76,668 KB
testcase_53 AC 1,536 ms
100,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from bisect import bisect_right
from heapq import *

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 SegtreeMax():
    def __init__(self, n):
        self.inf = 10 ** 16
        tree_width = 2
        while tree_width < n:
            tree_width *= 2
        self.tree_width = tree_width
        self.tree = [0] * (tree_width * 2 - 1)

    def update(self, i, a):
        seg_i = self.tree_width - 1 + i
        self.tree[seg_i] = a
        while seg_i != 0:
            seg_i = (seg_i - 1) // 2
            self.tree[seg_i] = max(self.tree[seg_i * 2 + 1], self.tree[seg_i * 2 + 2])

    def element(self, i):
        return self.tree[self.tree_width - 1 + i]

    def max(self, l, r, seg_i=0, segL=0, segR=-1):
        if segR == -1: segR = self.tree_width
        if r <= segL or segR <= l: return 0
        if l <= segL and segR <= r: return self.tree[seg_i]
        segM = (segL + segR) // 2
        ret0 = self.max(l, r, seg_i * 2 + 1, segL, segM)
        ret1 = self.max(l, r, seg_i * 2 + 2, segM, segR)
        return max(ret0, ret1)

def main():
    inf=10**15
    n=II()
    abci=[]
    for i in range(n):
        a,b,c=MI()
        abci.append((a,b,c,i))
    # aの小さいほうから見ていく
    # b-cが自分のaより小さければ、遷移先が出そろっているということなので
    # 遷移先の最大スコアにbを足して自分のスコアにする
    # スコアはセグメント木に入れておく
    # b-cがa以上であれば、b-c以下のaが出揃うまでhpに入れて保留する
    # 保留中はスコアをinfとしてセグメント木にいれておく
    # 保留中に自分への遷移があったときは、ループができるから
    abci.sort()
    ans=[0]*n
    st=SegtreeMax(n)
    hp=[]
    for j,(a,b,c,i) in enumerate(abci):
        # 保留中から出せるものを処理
        while hp and hp[0][0]<a:
            _,pb,pj=heappop(hp)
            if pj+1<j:mx=max(st.max(0,pj),st.max(pj+1,j))
            else:mx=st.max(0,pj)
            if mx!=inf:mx+=pb
            st.update(pj,mx)
            ans[abci[pj][3]]=mx
        # すぐに処理できるもの
        if b-c<a:
            k=bisect_right(abci,(b-c,inf,0,0))
            mx=st.max(0,k)
            if mx!=inf:mx+=b
            st.update(j,mx)
            ans[i]=mx
        # 保留するもの
        else:
            st.update(j,inf)
            heappush(hp,(b-c,b,j))
    # 最後まで保留されたものの処理
    while hp:
        _, pb, pj = heappop(hp)
        st.update(pj,0)
        mx=st.max(0,n)
        if mx!=inf:mx+=pb
        st.update(pj,mx)
        ans[abci[pj][3]]=mx
    # 答えの出力
    for x in ans:
        if x==inf:print("BAN")
        else:print(x)

main()
0