結果
問題 | No.1826 Fruits Collecting |
ユーザー | 👑 tamato |
提出日時 | 2022-01-28 22:48:23 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,248 ms / 2,000 ms |
コード長 | 2,942 bytes |
コンパイル時間 | 331 ms |
コンパイル使用メモリ | 87,656 KB |
実行使用メモリ | 174,288 KB |
最終ジャッジ日時 | 2023-08-28 21:21:50 |
合計ジャッジ時間 | 26,715 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 88 ms
76,660 KB |
testcase_01 | AC | 107 ms
78,680 KB |
testcase_02 | AC | 108 ms
78,664 KB |
testcase_03 | AC | 112 ms
78,744 KB |
testcase_04 | AC | 90 ms
76,596 KB |
testcase_05 | AC | 489 ms
115,548 KB |
testcase_06 | AC | 789 ms
147,040 KB |
testcase_07 | AC | 567 ms
124,836 KB |
testcase_08 | AC | 145 ms
81,412 KB |
testcase_09 | AC | 786 ms
139,272 KB |
testcase_10 | AC | 532 ms
119,592 KB |
testcase_11 | AC | 513 ms
119,844 KB |
testcase_12 | AC | 248 ms
95,036 KB |
testcase_13 | AC | 176 ms
84,340 KB |
testcase_14 | AC | 215 ms
88,836 KB |
testcase_15 | AC | 1,208 ms
173,644 KB |
testcase_16 | AC | 1,203 ms
174,288 KB |
testcase_17 | AC | 1,225 ms
173,780 KB |
testcase_18 | AC | 1,207 ms
173,488 KB |
testcase_19 | AC | 1,215 ms
173,832 KB |
testcase_20 | AC | 1,248 ms
174,228 KB |
testcase_21 | AC | 1,219 ms
173,568 KB |
testcase_22 | AC | 1,222 ms
174,236 KB |
testcase_23 | AC | 1,193 ms
173,748 KB |
testcase_24 | AC | 1,158 ms
173,588 KB |
testcase_25 | AC | 72 ms
71,848 KB |
testcase_26 | AC | 70 ms
71,708 KB |
testcase_27 | AC | 69 ms
71,864 KB |
testcase_28 | AC | 72 ms
71,880 KB |
testcase_29 | AC | 71 ms
71,776 KB |
testcase_30 | AC | 281 ms
102,060 KB |
testcase_31 | AC | 456 ms
119,972 KB |
testcase_32 | AC | 304 ms
98,648 KB |
testcase_33 | AC | 864 ms
146,860 KB |
testcase_34 | AC | 761 ms
126,740 KB |
testcase_35 | AC | 223 ms
90,144 KB |
testcase_36 | AC | 877 ms
146,684 KB |
testcase_37 | AC | 502 ms
129,172 KB |
testcase_38 | AC | 371 ms
113,640 KB |
testcase_39 | AC | 311 ms
121,168 KB |
testcase_40 | AC | 369 ms
126,956 KB |
testcase_41 | AC | 159 ms
88,976 KB |
testcase_42 | AC | 113 ms
78,936 KB |
testcase_43 | AC | 74 ms
71,424 KB |
testcase_44 | AC | 72 ms
71,572 KB |
testcase_45 | AC | 75 ms
71,724 KB |
ソースコード
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline class SegmentTree: def __init__(self, A, initialize=True, segfunc=max, ident=-10 ** 18): self.N = len(A) self.LV = (self.N - 1).bit_length() self.N0 = 1 << self.LV self.segfunc = segfunc self.ident = ident if initialize: self.data = [self.ident] * self.N0 + A + [self.ident] * (self.N0 - self.N) for i in range(self.N0 - 1, 0, -1): self.data[i] = segfunc(self.data[i * 2], self.data[i * 2 + 1]) else: self.data = [self.ident] * (self.N0 * 2) def update(self, i, x): i += self.N0 - 1 self.data[i] = x for _ in range(self.LV): i >>= 1 self.data[i] = self.segfunc(self.data[i * 2], self.data[i * 2 + 1]) def get(self, i): return self.data[i + self.N0 - 1] # open interval [l, r) def query(self, l, r): l += self.N0 - 1 r += self.N0 - 1 ret_l = self.ident ret_r = self.ident while l < r: if l & 1: ret_l = self.segfunc(ret_l, self.data[l]) l += 1 if r & 1: ret_r = self.segfunc(self.data[r - 1], ret_r) r -= 1 l >>= 1 r >>= 1 return self.segfunc(ret_l, ret_r) # return smallest i(l <= i < r) s.t. check(A[i]) == True def binsearch(self, l, r, check): if not check(self.query(l, r)): return r l += self.N0 - 1 val = self.ident while True: if check(self.segfunc(val, self.data[l])): break if l & 1: val = self.segfunc(val, self.data[l]) l += 1 l >>= 1 while l < self.N0: newval = self.segfunc(val, self.data[l * 2]) if not check(newval): val = newval l = (l << 1) + 1 else: l <<= 1 return l - self.N0 + 1 N = int(input()) XYV = [] Y = {0} for _ in range(N): t, x, v = map(int, input().split()) xx = t - x yy = t + x XYV.append((xx, yy, v)) Y.add(yy) XYV.sort(key=lambda z: z[1]) XYV.sort(key=lambda z: z[0]) Y = sorted(list(Y)) idx = {y: i + 1 for i, y in enumerate(Y)} L = len(Y) ST = SegmentTree([-10 ** 17] * L) ST.update(idx[0], 0) for x, y, v in XYV: if x < 0: continue i = idx[y] val = ST.query(1, i + 1) ST.update(i, val + v) print(ST.query(1, L+1)) if __name__ == '__main__': main()