結果
問題 | No.844 split game |
ユーザー | stng |
提出日時 | 2022-07-16 17:26:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 9,759 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 107,008 KB |
最終ジャッジ日時 | 2024-06-28 17:15:53 |
合計ジャッジ時間 | 23,742 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 446 ms
89,856 KB |
testcase_01 | AC | 399 ms
95,140 KB |
testcase_02 | AC | 723 ms
98,560 KB |
testcase_03 | AC | 603 ms
98,756 KB |
testcase_04 | AC | 398 ms
89,084 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 847 ms
106,108 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 870 ms
106,284 KB |
testcase_19 | AC | 891 ms
106,624 KB |
testcase_20 | AC | 880 ms
106,028 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 219 ms
79,488 KB |
testcase_27 | WA | - |
testcase_28 | AC | 166 ms
79,224 KB |
testcase_29 | AC | 237 ms
80,768 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 199 ms
79,880 KB |
testcase_33 | AC | 223 ms
80,328 KB |
testcase_34 | AC | 191 ms
78,884 KB |
testcase_35 | AC | 228 ms
80,000 KB |
testcase_36 | AC | 204 ms
79,164 KB |
testcase_37 | AC | 263 ms
81,488 KB |
testcase_38 | AC | 400 ms
85,760 KB |
testcase_39 | AC | 708 ms
93,952 KB |
testcase_40 | AC | 325 ms
88,192 KB |
testcase_41 | AC | 39 ms
53,888 KB |
testcase_42 | AC | 39 ms
54,400 KB |
testcase_43 | AC | 40 ms
53,632 KB |
testcase_44 | AC | 41 ms
54,272 KB |
testcase_45 | AC | 41 ms
54,228 KB |
testcase_46 | AC | 40 ms
54,016 KB |
testcase_47 | AC | 41 ms
53,760 KB |
testcase_48 | WA | - |
testcase_49 | AC | 40 ms
54,144 KB |
testcase_50 | AC | 40 ms
54,272 KB |
testcase_51 | AC | 40 ms
54,144 KB |
testcase_52 | AC | 40 ms
54,016 KB |
testcase_53 | AC | 41 ms
54,144 KB |
testcase_54 | AC | 41 ms
53,504 KB |
testcase_55 | AC | 41 ms
55,296 KB |
testcase_56 | AC | 38 ms
54,144 KB |
testcase_57 | AC | 40 ms
54,528 KB |
testcase_58 | AC | 41 ms
54,400 KB |
testcase_59 | AC | 44 ms
55,552 KB |
ソースコード
n,m,a = map(int,input().split()) lrp = [[int(i)-1 for i in input().split()] for j in range(m)] 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 _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 class LazySegTree(SegTree): def __init__(self, N, op_data, u_data, op_lazy, u_lazy, op_merge): super().__init__(N, op_data, u_data) self.composition = op_lazy self.mapping = op_merge self.id = u_lazy self.lazy = [u_lazy] * self.size def _all_apply(self, i, F): # self.data[i] = self.mapping(F, self.data[i], self.len[i]) self.data[i] = self.mapping(F, self.data[i]) if i < self.size: self.lazy[i] = self.composition(F, self.lazy[i]) def _push(self, i): self._all_apply(i << 1, self.lazy[i]) self._all_apply(i << 1 | 1, self.lazy[i]) self.lazy[i] = self.id def update(self, p, x): """ data[p] = x とする (0-indexed)""" p += self.size for i in reversed(range(1, self.log + 1)): self._push(p >> i) self.data[p] = x for i in range(1, self.log + 1): self._update(p >> i) def apply(self, p, F): """ data[p]にFを作用させる(data[p] = op_merge(F, data[p])とする, 0-indexed) """ p += self.size for i in reversed(range(1, self.log + 1)): self._push(p >> i) # self.data[p] = self.mapping(F, self.data[p], self.len[p]) self.data[p] = self.mapping(F, self.data[p]) for i in range(1, self.log + 1): self._update(p >> i) def range_apply(self, l, r, F): """ i = l, l+1, ..., r-1 について、Fを作用させる(op_merge(F, data[i]), 0-indexed) """ if l == r: return l += self.size r += self.size for i in reversed(range(1, self.log + 1)): # too->down if ((l >> i) << i) != l: self._push(l >> i) if ((r >> i) << i) != r: self._push((r - 1) >> i) l2, r2 = l, r while l < r: if l & 1: self._all_apply(l, F) l += 1 if r & 1: r -= 1 self._all_apply(r, F) l >>= 1 r >>= 1 l, r = l2, r2 for i in range(1, self.log + 1): if ((l >> i) << i) != l: self._update(l >> i) if ((r >> i) << i) != r: self._update((r - 1) >> i) def get(self, p): """ data[p]を返す """ p += self.size for i in reversed(range(1, self.log + 1)): self._push(p >> i) return self.data[p] def prod(self, l, r): """ op_data(data[l], data[l+1], ..., data[r-1])を返す (0-indexed) l == rの時は単位元u_dataを返す """ if l == r: return self.e l += self.size r += self.size for i in reversed(range(1, self.log + 1)): if ((l >> i) << i) != l: self._push(l >> i) if ((r >> i) << i) != r: self._push(r >> i) sml = self.e smr = self.e 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 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 for i in reversed(range(1, self.log + 1)): self._push(l >> i) sm = self.e while True: while l % 2 == 0: l >>= 1 if not func(self.op(sm, self.data[[l]])): while l < self.size: self._push(l) 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 for i in reversed(range(1, self.log + 1)): self._push((r - 1) >> i) 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: self._push(r) 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 """ 遅延セグ木(ac-library移植) op_data(d_L, d_R) : d_Lとd_Rの二項演算, dataを返す op_lazy(lz_new, lz_orig) : lz_origにlz_newを作用させる, lazyを返す op_merge(lz, d) : dにlzを作用させる, dataを返す """ u_data = 0 op_data = max u_lazy = -1 def op_lazy(nw, od): if nw == -1: return od return nw def op_merge(lz, d): if lz == -1: return d return lz lrp.sort(key=lambda x:(x[1],x[0])) dp = [[-10**15]*2 for i in range(n+1)] dp[0][1] = 0 dp[n][1] = 0 for i in range(n): dp[i][0] = 0 mv = 0 seg = LazySegTree(n+1, op_data, u_data, op_lazy, u_lazy, op_merge) seg.initialize() for i in range(m): l,r,p = lrp[i] p += 1 r += 1 if l != 0: if r != n: dp[r][1] = max(dp[l][1]+p-a,max(seg.get(l),dp[l][0])+p-2*a,dp[r][1]) else: dp[r][1] = max(dp[l][1]+p,max(seg.get(l),dp[l][0])+p-a,dp[r][1]) else: if r != n: dp[r][1] = max(dp[l][1]+p-a,max(seg.get(l),dp[l][0])+p-a,dp[r][1]) else: dp[r][1] = max(dp[l][1]+p,max(seg.get(l),dp[l][0])+p,dp[r][1]) #mv = max(mv,dp[r][1]) #L, R = map(int, input().split()) #H = seg.prod(r, n+1) seg.range_apply(r, n+1, dp[r][1]) ans = 0 #print(dp) for i in range(n+1): ans = max(ans,dp[i][0],dp[i][1]) print(ans)