結果
問題 | No.59 鉄道の旅 |
ユーザー |
|
提出日時 | 2016-10-27 16:34:09 |
言語 | PyPy2 (7.3.15) |
結果 |
AC
|
実行時間 | 1,974 ms / 5,000 ms |
コード長 | 1,822 bytes |
コンパイル時間 | 1,963 ms |
コンパイル使用メモリ | 76,928 KB |
実行使用メモリ | 297,856 KB |
最終ジャッジ日時 | 2024-12-25 00:17:16 |
合計ジャッジ時間 | 19,121 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
class SegmentTree:class Node:def __init__(self, l, r, n):self.l = lself.r = rself.n = nself.left_child = Noneself.right_child = Nonedef update(self, i, n):if self.l <= i < self.r:self.n += nif self.right_child is None:returnif i < self.l+(self.r-self.l)/2:self.left_child.update(i, n)else:self.right_child.update(i, n)def get_sum(self, l, r):ret = 0if r <= self.l or self.r <= l:return 0elif l <= self.l and self.r <= r:return self.nelse:return self.left_child.get_sum(l, r) + self.right_child.get_sum(l, r)def __init__(self, n):m = 1while m < n:m *= 2self.root = self._construct(0, m)def _construct(self, l, r):node = self.Node(l, r, 0)if r-l <= 1:return nodemid = l+(r-l)/2node.left_child = self._construct(l, mid)node.right_child = self._construct(mid, r)return nodedef update(self, i, n):self.root.update(i, n)def get_sum(self, l, r):return self.root.get_sum(l, r)W_MAX = 1000001N, K = map(int, raw_input().split())sg = SegmentTree(W_MAX)ans = 0d = {}for _ in xrange(N):w = int(raw_input())#if w in d:# d[w] += 1#else:# d[w] = 1if w >= 0 and sg.get_sum(w, W_MAX) < K:ans += 1sg.update(w, 1)#print d#print w, sg.get_sum(w, W_MAX)elif w < 0 and sg.get_sum(-w, -w+1) > 0:ans -= 1sg.update(-w, -1)print ans