結果

問題 No.1826 Fruits Collecting
ユーザー tktk_snsntktk_snsn
提出日時 2022-01-28 22:31:20
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 814 ms / 2,000 ms
コード長 3,850 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 130,668 KB
最終ジャッジ日時 2023-08-28 20:41:35
合計ジャッジ時間 20,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
76,220 KB
testcase_01 AC 101 ms
76,460 KB
testcase_02 AC 101 ms
76,660 KB
testcase_03 AC 103 ms
76,792 KB
testcase_04 AC 86 ms
76,096 KB
testcase_05 AC 303 ms
91,008 KB
testcase_06 AC 453 ms
107,556 KB
testcase_07 AC 328 ms
96,372 KB
testcase_08 AC 136 ms
78,824 KB
testcase_09 AC 443 ms
106,260 KB
testcase_10 AC 327 ms
94,696 KB
testcase_11 AC 319 ms
92,300 KB
testcase_12 AC 200 ms
84,468 KB
testcase_13 AC 153 ms
80,124 KB
testcase_14 AC 175 ms
82,636 KB
testcase_15 AC 645 ms
117,000 KB
testcase_16 AC 636 ms
117,356 KB
testcase_17 AC 645 ms
117,092 KB
testcase_18 AC 629 ms
117,328 KB
testcase_19 AC 625 ms
117,428 KB
testcase_20 AC 647 ms
117,312 KB
testcase_21 AC 653 ms
116,960 KB
testcase_22 AC 644 ms
117,312 KB
testcase_23 AC 637 ms
117,236 KB
testcase_24 AC 640 ms
117,376 KB
testcase_25 AC 72 ms
71,124 KB
testcase_26 AC 74 ms
71,340 KB
testcase_27 AC 73 ms
71,108 KB
testcase_28 AC 71 ms
71,032 KB
testcase_29 AC 72 ms
71,344 KB
testcase_30 AC 171 ms
82,640 KB
testcase_31 AC 233 ms
85,780 KB
testcase_32 AC 292 ms
96,112 KB
testcase_33 AC 814 ms
130,668 KB
testcase_34 AC 692 ms
127,548 KB
testcase_35 AC 230 ms
88,768 KB
testcase_36 AC 803 ms
129,332 KB
testcase_37 AC 613 ms
121,332 KB
testcase_38 AC 450 ms
109,400 KB
testcase_39 AC 321 ms
111,184 KB
testcase_40 AC 379 ms
123,808 KB
testcase_41 AC 166 ms
87,372 KB
testcase_42 AC 121 ms
78,628 KB
testcase_43 AC 76 ms
70,972 KB
testcase_44 AC 74 ms
71,040 KB
testcase_45 AC 74 ms
70,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class SegTree(object):
    def __init__(self, N, op_data, u_data):
        self._n = N
        self.log = (N-1).bit_length()
        self.size = 1 << self.log

        self.op = op_data
        self.e = u_data

        self.data = [u_data] * (2 * self.size)
        # self.len = [1] * (2 * self.size)

    def __repr__(self):
        res = [self.get(i) for i in range(self._n)]
        return " ".join(map(str, res))

    def _update(self, i):
        self.data[i] = self.op(self.data[i << 1], self.data[i << 1 | 1])

    def initialize(self, arr=None):
        """ segtreeをarrで初期化する。len(arr) == Nにすること """
        if arr:
            for i, a in enumerate(arr, self.size):
                self.data[i] = a
        for i in reversed(range(1, self.size)):
            self._update(i)
            # self.len[i] = self.len[i << 1] + self.len[i << 1 | 1]

    def update(self, p, x):
        """ data[p] = x とする (0-indexed)"""
        p += self.size
        self.data[p] = x
        for i in range(1, self.log + 1):
            self._update(p >> i)

    def get(self, p):
        """ data[p]を返す """
        return self.data[p + self.size]

    def prod(self, l, r):
        """
        op_data(data[l], data[l+1], ..., data[r-1])を返す (0-indexed)
        """
        sml = self.e
        smr = self.e
        l += self.size
        r += self.size

        while l < r:
            if l & 1:
                sml = self.op(sml, self.data[l])
                l += 1
            if r & 1:
                r -= 1
                smr = self.op(self.data[r], smr)
            l >>= 1
            r >>= 1
        return self.op(sml, smr)

    def all_prod(self):
        """ op(data[0], data[1], ... data[N-1])を返す """
        return self.data[1]

    def max_right(self, l, func):
        """
        func(l, l+1, ..., r-1) = True,
        func(l, l+1, ..., r-1, r) = Falseとなる r を返す
        """
        if l == self._n:
            return self._n
        l += self.size
        sm = self.e
        while True:
            while l % 2 == 0:
                l >>= 1
            if not func(self.op(sm, self.data[l])):
                while l < self.size:
                    l <<= 1
                    if func(self.op(sm, self.data[l])):
                        sm = self.op(sm, self.data[l])
                        l += 1
                return l - self.size
            sm = self.op(sm, self.data[l])
            l += 1
            if (l & -l) == l:
                break
        return self._n

    def min_left(self, r, func):
        """
        func(     l, l+1, ..., r-1) = True,
        func(l-1, l, l+1, ..., r-1) = Falseとなる l を返す
        """
        if r == 0:
            return 0
        r += self.size
        sm = self.e
        while True:
            r -= 1
            while r > 1 and r & 1:
                r >>= 1
            if not func(self.op(self.data[r], sm)):
                while r < self.size:
                    r = r << 1 | 1
                    if func(self.op(self.data[r], sm)):
                        sm = self.op(self.data[r], sm)
                        r -= 1
                return r + 1 - self.size
            sm = self.op(self.data[r], sm)
            if (r & -r) == r:
                break
        return 0


"""
45°回転すると平面操作っぽくなる
"""

N = int(input())
TXV = []
memo = {0, }

for _ in range(N):
    t, x, v = map(int, input().split())
    if abs(x) <= t:
        TXV.append((t + x, t - x, v))
        memo.add(t - x)

TXV.sort()
memo = sorted(memo)
mtoi = {m: i for i, m in enumerate(memo)}

seg = SegTree(len(memo), max, 0)
for _, x, v in TXV:
    i = mtoi[x]
    val = v + seg.prod(0, i + 1)
    seg.update(i, val)
print(seg.all_prod())
0