結果

問題 No.54 Happy Hallowe'en
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-01-01 14:42:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,426 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 79,020 KB
最終ジャッジ日時 2024-04-18 11:27:24
合計ジャッジ時間 2,669 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,516 KB
testcase_01 AC 36 ms
54,140 KB
testcase_02 AC 35 ms
53,432 KB
testcase_03 WA -
testcase_04 AC 91 ms
77,588 KB
testcase_05 AC 100 ms
77,944 KB
testcase_06 AC 112 ms
78,564 KB
testcase_07 AC 121 ms
78,848 KB
testcase_08 AC 123 ms
78,688 KB
testcase_09 AC 129 ms
79,020 KB
testcase_10 AC 37 ms
54,312 KB
testcase_11 AC 37 ms
53,068 KB
testcase_12 AC 97 ms
78,160 KB
testcase_13 AC 101 ms
78,740 KB
testcase_14 AC 36 ms
53,160 KB
testcase_15 AC 36 ms
53,096 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:
    """ define what you want to do with 0 index, ex) size = tree_size, func = min or max, sta = default_value """
    
    def __init__(self,size,func,sta):
        self.n = size
        self.size = 1 << size.bit_length()
        self.func = func
        self.sta = sta
        self.tree = [sta]*(2*self.size)

    def build(self, list):
        """ set list and update tree"""
        for i,x in enumerate(list,self.size):
            self.tree[i] = x

        for i in range(self.size-1,0,-1):
            self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1])

    def set(self,i,x):
        i += self.size
        self.tree[i] = max(self.tree[i],x)
        while i > 1:
            i >>= 1
            self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1])

    
    def get(self,l,r):
        """ take the value of [l r) with func (min or max)"""
        l += self.size
        r += self.size
        res = self.sta

        while l < r:
            if l & 1:
                res = self.func(self.tree[l],res)
                l += 1
            if r & 1:
                res = self.func(self.tree[r-1],res)
            l >>= 1
            r >>= 1
        return res

n = int(input())
VT = [list(map(int,input().split())) for i in range(n)]
VT.sort(key=lambda x: x[0]+x[1])

seg = SegTree(2*10**4+5,max,0)
for v,t in VT:
    m = seg.get(0,t)
    seg.set(m+v,m+v)

print(seg.get(0,2*10**4+4))

0