結果
| 問題 |
No.1826 Fruits Collecting
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2022-01-29 01:39:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,619 ms / 2,000 ms |
| コード長 | 1,358 bytes |
| コンパイル時間 | 439 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 268,764 KB |
| 最終ジャッジ日時 | 2024-12-30 18:48:25 |
| 合計ジャッジ時間 | 34,279 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
import sys
input = sys.stdin.readline
from operator import itemgetter
N=int(input())
B=[list(map(int,input().split())) for i in range(N)]
B2=[[0,0,0]]
for t,x,v in B:
B2.append([t+x,t-x,v])
#print(B2)
SS=[0]
for x,y,v in B2:
SS.append(x)
SS.append(y)
SS=sorted(set(SS))
D={SS[i]:i for i in range(len(SS))}
for i in range(N+1):
B2[i][0]=D[B2[i][0]]
B2[i][1]=D[B2[i][1]]
#print(B2)
B2.sort()
def seg_function(x,y): # Segment treeで扱うfunction
return max(x,y)
seg_el=1<<((len(SS)+5).bit_length()) # Segment treeの台の要素数
SEG=[-1<<60]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
def update(n,x,seg_el): # A[n]をxへ更新
i=n+seg_el
SEG[i]=x
i>>=1 # 子ノードへ
while i!=0:
SEG[i]=seg_function(SEG[i*2],SEG[i*2+1])
i>>=1
def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる
L=l+seg_el
R=r+seg_el
ANS=-1<<60
while L<R:
if L & 1:
ANS=seg_function(ANS , SEG[L])
L+=1
if R & 1:
R-=1
ANS=seg_function(ANS , SEG[R])
L>>=1
R>>=1
return ANS
update(D[0],0,seg_el)
for x,y,v in B2:
if x<D[0]:
continue
A=getvalues(0,y+1)
#print(x,y,v,A)
update(y,A+v,seg_el)
print(SEG[1])
titia