結果

問題 No.1014 competitive fighting
ユーザー mkawa2mkawa2
提出日時 2020-03-24 12:10:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,565 ms / 2,000 ms
コード長 3,075 bytes
コンパイル時間 451 ms
コンパイル使用メモリ 86,688 KB
実行使用メモリ 109,424 KB
最終ジャッジ日時 2023-09-21 19:28:25
合計ジャッジ時間 36,826 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
70,752 KB
testcase_01 AC 75 ms
71,208 KB
testcase_02 AC 75 ms
70,936 KB
testcase_03 AC 82 ms
70,928 KB
testcase_04 AC 78 ms
70,740 KB
testcase_05 AC 1,565 ms
104,188 KB
testcase_06 AC 1,483 ms
103,708 KB
testcase_07 AC 1,386 ms
101,596 KB
testcase_08 AC 1,359 ms
101,888 KB
testcase_09 AC 1,386 ms
101,860 KB
testcase_10 AC 726 ms
109,424 KB
testcase_11 AC 328 ms
95,920 KB
testcase_12 AC 1,360 ms
102,740 KB
testcase_13 AC 740 ms
91,676 KB
testcase_14 AC 644 ms
89,724 KB
testcase_15 AC 823 ms
92,208 KB
testcase_16 AC 183 ms
79,720 KB
testcase_17 AC 387 ms
84,228 KB
testcase_18 AC 1,151 ms
99,376 KB
testcase_19 AC 1,268 ms
102,056 KB
testcase_20 AC 580 ms
87,680 KB
testcase_21 AC 1,026 ms
96,736 KB
testcase_22 AC 848 ms
93,140 KB
testcase_23 AC 475 ms
86,484 KB
testcase_24 AC 484 ms
85,660 KB
testcase_25 AC 262 ms
81,220 KB
testcase_26 AC 1,088 ms
97,696 KB
testcase_27 AC 388 ms
83,084 KB
testcase_28 AC 428 ms
86,820 KB
testcase_29 AC 143 ms
78,636 KB
testcase_30 AC 1,311 ms
101,112 KB
testcase_31 AC 1,064 ms
96,616 KB
testcase_32 AC 126 ms
77,524 KB
testcase_33 AC 127 ms
78,240 KB
testcase_34 AC 446 ms
92,780 KB
testcase_35 AC 593 ms
96,168 KB
testcase_36 AC 403 ms
91,860 KB
testcase_37 AC 134 ms
78,164 KB
testcase_38 AC 397 ms
88,896 KB
testcase_39 AC 272 ms
84,024 KB
testcase_40 AC 378 ms
88,760 KB
testcase_41 AC 295 ms
86,420 KB
testcase_42 AC 540 ms
95,500 KB
testcase_43 AC 126 ms
78,604 KB
testcase_44 AC 503 ms
93,720 KB
testcase_45 AC 361 ms
87,876 KB
testcase_46 AC 145 ms
78,820 KB
testcase_47 AC 236 ms
82,900 KB
testcase_48 AC 444 ms
91,724 KB
testcase_49 AC 120 ms
78,040 KB
testcase_50 AC 523 ms
93,836 KB
testcase_51 AC 334 ms
87,028 KB
testcase_52 AC 122 ms
78,136 KB
testcase_53 AC 1,486 ms
101,736 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