結果

問題 No.1014 competitive fighting
ユーザー mkawa2mkawa2
提出日時 2020-03-24 11:13:13
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,174 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 153,056 KB
最終ジャッジ日時 2023-08-30 05:15:36
合計ジャッジ時間 13,896 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,468 KB
testcase_01 AC 79 ms
71,216 KB
testcase_02 AC 80 ms
71,248 KB
testcase_03 AC 80 ms
71,216 KB
testcase_04 AC 79 ms
71,408 KB
testcase_05 AC 1,321 ms
135,100 KB
testcase_06 AC 1,229 ms
136,008 KB
testcase_07 AC 1,334 ms
134,828 KB
testcase_08 AC 1,209 ms
135,144 KB
testcase_09 AC 1,241 ms
135,500 KB
testcase_10 TLE -
testcase_11 AC 251 ms
118,728 KB
testcase_12 AC 1,355 ms
136,052 KB
testcase_13 AC 698 ms
106,248 KB
testcase_14 AC 619 ms
104,376 KB
testcase_15 AC 766 ms
109,136 KB
testcase_16 AC 238 ms
83,384 KB
testcase_17 AC 406 ms
91,608 KB
testcase_18 AC 1,096 ms
127,388 KB
testcase_19 AC 1,276 ms
134,404 KB
testcase_20 AC 569 ms
100,764 KB
testcase_21 AC 1,013 ms
125,664 KB
testcase_22 AC 853 ms
111,816 KB
testcase_23 AC 446 ms
93,568 KB
testcase_24 AC 414 ms
93,832 KB
testcase_25 AC 238 ms
83,116 KB
testcase_26 AC 949 ms
125,684 KB
testcase_27 AC 380 ms
91,048 KB
testcase_28 AC 409 ms
91,712 KB
testcase_29 AC 158 ms
79,488 KB
testcase_30 AC 1,238 ms
132,964 KB
testcase_31 AC 1,064 ms
127,116 KB
testcase_32 AC 140 ms
78,324 KB
testcase_33 AC 143 ms
80,412 KB
testcase_34 AC 495 ms
113,832 KB
testcase_35 AC 663 ms
119,504 KB
testcase_36 AC 412 ms
110,568 KB
testcase_37 AC 135 ms
79,252 KB
testcase_38 AC 428 ms
103,060 KB
testcase_39 AC 339 ms
92,892 KB
testcase_40 AC 363 ms
101,644 KB
testcase_41 AC 293 ms
97,548 KB
testcase_42 AC 508 ms
119,056 KB
testcase_43 AC 129 ms
79,752 KB
testcase_44 AC 527 ms
115,624 KB
testcase_45 AC 415 ms
101,092 KB
testcase_46 AC 140 ms
81,128 KB
testcase_47 AC 275 ms
90,212 KB
testcase_48 AC 558 ms
112,756 KB
testcase_49 AC 137 ms
79,388 KB
testcase_50 AC 496 ms
115,776 KB
testcase_51 AC 298 ms
98,952 KB
testcase_52 AC 123 ms
78,788 KB
testcase_53 AC 1,271 ms
135,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_right
from heapq import *
import sys

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]

def main():
    def connect(j,l,r,sl=0,sr=-1,si=0):
        if l>=r:return
        if sr==-1:sr=w
        if r<=sl or sr<=l:return
        if l<=sl and sr<=r:
            to[j+w-1].append(si)
            return
        sm=(sl+sr)//2
        connect(j,l,r,sl,sm,si*2+1)
        connect(j,l,r,sm,sr,si*2+2)

    def dfs(u):
        vis[u]=0
        for v in to[u]:
            if vis[v]==0:
                dp[u]=inf
                break
            if vis[v]==-1:
                dfs(v)
            if dp[v]==inf:
                dp[u]=inf
                break
            dp[u]=max(dp[u],dp[v])
        if u>=w-1:
            _,b,_,i=abci[u-w+1]
            if dp[u]!=inf:dp[u]+=b
            ans[i]=dp[u]
        vis[u] = 1

    inf=10**15
    n=II()
    abci=[]
    w=1<<(n-1).bit_length()
    to=[[] for _ in range(w-1+n)]
    for i in range(w-2+n,0,-1):to[(i-1)//2].append(i)
    for i in range(n):
        a,b,c=MI()
        abci.append((a,b,c,i))
    # aの小さい順に見ていってセグメント木に辺を張る
    abci.sort()
    aa=[]
    hp=[]
    for j,(a,b,c,i) in enumerate(abci):
        while hp and hp[0][0]<a:
            _,pj=heappop(hp)
            connect(pj,0,pj)
            connect(pj,pj+1,j)
        if b-c<a:
            k=bisect_right(aa,b-c)
            connect(j,0,k)
        else:
            heappush(hp,(b-c,j))
        aa.append(a)
    while hp:
        _, pj = heappop(hp)
        connect(pj, 0, pj)
        connect(pj, pj + 1, n)
    # dfsで最大スコアを求める
    dp=[0]*(2*w-1)
    vis=[-1]*(2*w-1)
    ans=[0]*n
    for u in range(w-1,w-1+n):
        if vis[u]!=-1:continue
        dfs(u)
    # 答えの出力
    for x in ans:
        if x==inf:print("BAN")
        else:print(x)

main()
0