結果
問題 | No.59 鉄道の旅 |
ユーザー | Navier_Boltzmann |
提出日時 | 2023-07-15 14:50:32 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 265 ms / 5,000 ms |
コード長 | 2,089 bytes |
コンパイル時間 | 233 ms |
コンパイル使用メモリ | 81,780 KB |
実行使用メモリ | 110,220 KB |
最終ジャッジ日時 | 2023-10-17 00:01:20 |
合計ジャッジ時間 | 3,047 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
55,740 KB |
testcase_01 | AC | 41 ms
55,740 KB |
testcase_02 | AC | 41 ms
55,740 KB |
testcase_03 | AC | 42 ms
57,788 KB |
testcase_04 | AC | 265 ms
110,220 KB |
testcase_05 | AC | 45 ms
57,804 KB |
testcase_06 | AC | 44 ms
57,804 KB |
testcase_07 | AC | 44 ms
57,804 KB |
testcase_08 | AC | 113 ms
78,896 KB |
testcase_09 | AC | 115 ms
78,368 KB |
testcase_10 | AC | 125 ms
78,116 KB |
testcase_11 | AC | 80 ms
76,780 KB |
testcase_12 | AC | 115 ms
78,784 KB |
testcase_13 | AC | 201 ms
96,208 KB |
testcase_14 | AC | 211 ms
97,760 KB |
testcase_15 | AC | 41 ms
55,756 KB |
ソースコード
from collections import * from itertools import * from functools import * from heapq import * import sys,math N,K = map(int,input().split()) W = [int(input()) for _ in range(N)] X = W[:] X = [abs(i) for i in X] X = list(set(X)) X.sort() conv = {x:i for i,x in enumerate(X)} n = len(X) val = defaultdict(int) class SegTree: """ Segment Tree """ def __init__(self, init_val, segfunc, ide_ele): """ 初期化 init_val: 配列の初期値 """ n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num # 配列の値を葉にセット for i in range(n): self.tree[self.num + i] = init_val[i] # 構築していく for i in range(self.num - 1, 0, -1): self.tree[i] = segfunc(self.tree[2 * i], self.tree[2 * i + 1]) def update(self, k, x): """ k番目の値をxに更新 k: index(0-index) x: update value """ k += self.num self.tree[k] = x while k > 1: self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1]) k >>= 1 def query(self, l, r): """ [l, r)のsegfuncしたものを得る l: index(0-index) r: index(0-index) """ res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res T = SegTree([0]*n,lambda x,y:x+y, 0) for w in W: if w<0: w *= -1 if val[w]==0: continue val[w] -= 1 idx = conv[w] T.update(idx,val[w]) else: idx = conv[w] if T.query(idx,n)>=K: continue val[w] += 1 T.update(idx,val[w]) print(T.query(0,n))