結果

問題 No.1014 competitive fighting
ユーザー mkawa2mkawa2
提出日時 2020-03-23 23:57:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,217 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 149,528 KB
最終ジャッジ日時 2023-08-28 15:09:41
合計ジャッジ時間 36,419 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,336 KB
testcase_01 AC 75 ms
71,388 KB
testcase_02 AC 75 ms
71,424 KB
testcase_03 AC 74 ms
71,180 KB
testcase_04 AC 75 ms
71,512 KB
testcase_05 AC 1,241 ms
136,012 KB
testcase_06 AC 1,193 ms
136,344 KB
testcase_07 AC 1,249 ms
134,580 KB
testcase_08 AC 1,138 ms
135,012 KB
testcase_09 AC 1,148 ms
135,516 KB
testcase_10 AC 1,761 ms
149,528 KB
testcase_11 AC 244 ms
118,408 KB
testcase_12 AC 1,297 ms
135,444 KB
testcase_13 AC 662 ms
107,364 KB
testcase_14 AC 608 ms
104,208 KB
testcase_15 AC 742 ms
108,008 KB
testcase_16 AC 227 ms
83,048 KB
testcase_17 AC 396 ms
91,048 KB
testcase_18 AC 1,092 ms
129,508 KB
testcase_19 AC 1,239 ms
134,208 KB
testcase_20 AC 565 ms
101,000 KB
testcase_21 AC 896 ms
124,608 KB
testcase_22 AC 844 ms
111,380 KB
testcase_23 AC 448 ms
93,136 KB
testcase_24 AC 403 ms
93,528 KB
testcase_25 AC 235 ms
82,400 KB
testcase_26 AC 943 ms
126,076 KB
testcase_27 AC 367 ms
91,020 KB
testcase_28 AC 390 ms
91,896 KB
testcase_29 AC 157 ms
79,296 KB
testcase_30 AC 1,196 ms
132,848 KB
testcase_31 AC 1,087 ms
126,784 KB
testcase_32 AC 137 ms
78,300 KB
testcase_33 AC 140 ms
80,120 KB
testcase_34 AC 451 ms
112,228 KB
testcase_35 WA -
testcase_36 AC 404 ms
110,404 KB
testcase_37 AC 132 ms
79,144 KB
testcase_38 WA -
testcase_39 AC 314 ms
92,136 KB
testcase_40 AC 361 ms
101,884 KB
testcase_41 AC 288 ms
97,208 KB
testcase_42 AC 485 ms
118,396 KB
testcase_43 AC 124 ms
79,700 KB
testcase_44 AC 520 ms
115,576 KB
testcase_45 WA -
testcase_46 AC 133 ms
80,796 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 131 ms
79,224 KB
testcase_50 AC 484 ms
115,368 KB
testcase_51 AC 301 ms
98,816 KB
testcase_52 AC 119 ms
78,604 KB
testcase_53 AC 1,249 ms
134,820 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 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,start=-1):
        if start==-1:start=u
        for v in to[u]:
            if vis[v]==start:
                dp[u]=inf
                break
            if vis[v]==-1:
                vis[v]=start
                dfs(v,start)
            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]

    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 j in range(n):
        u=j+w-1
        if vis[u]!=-1:continue
        vis[u]=u
        dfs(u)
    # 答えの出力
    for x in ans:
        if x==inf:print("BAN")
        else:print(x)

main()
0