提出 #33353118
ソースコード 拡げる
'''
oj(online-judge-tools)の使い方について
1. テストケースをダウンロード
2. サンプルが合っているかジャッジする
3. 提出する
oj d https://atcoder.jp/contests/abc260/tasks/abc260_d
oj t -c "python3 D.py"
oj s https://atcoder.jp/contests/abc260/tasks/abc260_d D.py --guess-python-interpreter pypy
※test/ が既に作成されている場合は下記コマンドで test/ を削除する
rm -rf test/
'''
import sys
input = sys.stdin.readline
sys.setrecursionlimit(500_000)
printd = lambda *x : print(*x, file = sys.stderr)
from math import sqrt, ceil, floor, sin, cos, tan, acos, asin, atan, radians, factorial, exp, degrees
from collections import defaultdict, deque, Counter
from itertools import product, permutations, combinations, combinations_with_replacement
from heapq import heapify, heappop, heappush
from bisect import bisect, bisect_left, bisect_right
def ceil(a: int, b: int) -> int:
"calc ceil(b / a)"
return (a + b - 1) // a
# 99.99% tatyam さんが公開されている SortedSet を使用しています
# 一部自分用に変換しています
# https://github.com/tatyam-prime/SortedSet/blob/main/SortedSet.py
# https://qiita.com/tatyam/items/492c70ac4c955c055602
'''
SortedSetの使用例
ABC217-D - CuttingWoods https://atcoder.jp/contests/abc217/tasks/abc217_d
'''
from math import ceil, sqrt
from bisect import bisect_left, bisect_right
from typing import Generic, Iterable, Iterator, TypeVar, Union, List
T = TypeVar('T')
class SortedSet(Generic[T]):
BUCKET_RATIO = 50
REBUILD_RATIO = 170
def _build(self, a=None) -> None:
"Evenly divide `a` into buckets."
if a is None:
a = list(self)
size = self.size = len(a)
bucket_size = int(ceil(sqrt(size / self.BUCKET_RATIO)))
self.a = [a[size * i // bucket_size : size * (i + 1) // bucket_size] for i in range(bucket_size)]
def __init__(self, a: Iterable[T] = []) -> None:
"Make a new SortedSet from iterable. / O(N) if sorted and unique / O(N log N)"
a = list(a)
if not all(a[i] < a[i + 1] for i in range(len(a) - 1)):
a = sorted(set(a))
self._build(a)
def __iter__(self) -> Iterator[T]:
for i in self.a:
for j in i:
yield j
def __reversed__(self) -> Iterator[T]:
for i in reversed(self.a):
for j in reversed(i):
yield j
def __len__(self) -> int:
return self.size
def __repr__(self) -> str:
return "SortedSet" + str(self.a)
def __str__(self) -> str:
s = str(list(self))
return "{" + s[1 : len(s) - 1] + "}"
def _find_bucket(self, x: T) -> List[T]:
"Find the bucket which should contain x. self must not be empty."
for a in self.a:
if x <= a[-1]:
return a
return a
def __contains__(self, x: T) -> bool:
if self.size == 0:
return False
a = self._find_bucket(x)
i = bisect_left(a, x)
return i != len(a) and a[i] == x
def add(self, x: T) -> bool:
"Add an element and return True if added. / O(√N)"
if self.size == 0:
self.a = [[x]]
self.size = 1
return True
a = self._find_bucket(x)
i = bisect_left(a, x)
if i != len(a) and a[i] == x:
return False
a.insert(i, x)
self.size += 1
if len(a) > len(self.a) * self.REBUILD_RATIO:
self._build()
return True
def discard(self, x: T) -> bool:
"Remove an element and return True if removed. / O(√N)"
if self.size == 0:
return False
a = self._find_bucket(x)
i = bisect_left(a, x)
if i == len(a) or a[i] != x:
return False
a.pop(i)
self.size -= 1
if len(a) == 0:
self._build()
return True
def lt(self, x: T) -> Union[T, None]:
"Find the largest element < x, or None if it doesn't exist."
for a in reversed(self.a):
if a[0] < x:
return a[bisect_left(a, x) - 1]
def le(self, x: T) -> Union[T, None]:
"Find the largest element <= x, or None if it doesn't exist."
for a in reversed(self.a):
if a[0] <= x:
return a[bisect_right(a, x) - 1]
def gt(self, x: T) -> Union[T, None]:
"Find the smallest element > x, or None if it doesn't exist."
for a in self.a:
if a[-1] > x:
return a[bisect_right(a, x)]
def ge(self, x: T) -> Union[T, None]:
"Find the smallest element >= x, or None if it doesn't exist."
for a in self.a:
if a[-1] >= x:
return a[bisect_left(a, x)]
def __getitem__(self, x: int) -> T:
"Return the x-th element, or IndexError if it doesn't exist."
if x < 0:
x += self.size
if x < 0:
raise IndexError
for a in self.a:
if x < len(a):
return a[x]
x -= len(a)
raise IndexError
def index(self, x: T) -> int:
"Count the number of elements < x."
ans = 0
for a in self.a:
if a[-1] >= x:
return ans + bisect_left(a, x)
ans += len(a)
return ans
def index_right(self, x: T) -> int:
"Count the number of elements <= x."
ans = 0
for a in self.a:
if a[-1] > x:
return ans + bisect_right(a, x)
ans += len(a)
return ans
def main() -> None:
INF = float('inf')
mod = 1000000007
#mod = 998244353
#n = int(input())
#s = input()
n, k = map(int, input().split())
p = list(map(int, input().split()))
#a = [list(map(int, input().split())) for _ in range(n)]
#s = [list(input()) for _ in range(h)]
#grid = [list(input()) for _ in range(h)]
d = defaultdict(list)
ans = [-1] * n
s = SortedSet()
for i in range(n):
key = s.ge(p[i])
if key == None:
d[p[i]].append(p[i])
s.add(p[i])
else:
d[p[i]] = d[key]
d[key] = []
d[p[i]].append(p[i])
s.add(p[i])
s.discard(key)
if len(d[p[i]]) == k:
for j in range(len(d[p[i]])):
ans[d[p[i]][j] - 1] = i + 1
s.discard(d[p[i]][j])
d[p[i]] = []
print(*ans, sep="\n")
if __name__ == '__main__':
main()
提出情報
ジャッジ結果
セット名 |
Sample |
All |
得点 / 配点 |
0 / 0 |
400 / 400 |
結果 |
|
|
セット名 |
テストケース |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt |
ケース名 |
結果 |
実行時間 |
メモリ |
sample_01.txt |
AC |
104 ms |
74892 KiB |
sample_02.txt |
AC |
86 ms |
74928 KiB |
sample_03.txt |
AC |
90 ms |
75144 KiB |
test_01.txt |
AC |
85 ms |
74896 KiB |
test_02.txt |
AC |
96 ms |
75076 KiB |
test_03.txt |
AC |
89 ms |
74688 KiB |
test_04.txt |
AC |
99 ms |
75088 KiB |
test_05.txt |
AC |
93 ms |
75104 KiB |
test_06.txt |
AC |
272 ms |
101224 KiB |
test_07.txt |
AC |
330 ms |
131604 KiB |
test_08.txt |
AC |
310 ms |
112140 KiB |
test_09.txt |
AC |
240 ms |
105316 KiB |
test_10.txt |
AC |
281 ms |
104428 KiB |
test_11.txt |
AC |
173 ms |
82648 KiB |
test_12.txt |
AC |
401 ms |
133516 KiB |
test_13.txt |
AC |
273 ms |
110100 KiB |
test_14.txt |
AC |
431 ms |
137692 KiB |
test_15.txt |
AC |
244 ms |
106072 KiB |
test_16.txt |
AC |
381 ms |
136188 KiB |
test_17.txt |
AC |
409 ms |
136940 KiB |
test_18.txt |
AC |
438 ms |
144984 KiB |
test_19.txt |
AC |
306 ms |
138360 KiB |
test_20.txt |
AC |
412 ms |
137500 KiB |
test_21.txt |
AC |
357 ms |
137056 KiB |
test_22.txt |
AC |
446 ms |
144728 KiB |
test_23.txt |
AC |
406 ms |
137804 KiB |
test_24.txt |
AC |
477 ms |
146568 KiB |
test_25.txt |
AC |
266 ms |
130672 KiB |
test_26.txt |
AC |
413 ms |
136628 KiB |
test_27.txt |
AC |
341 ms |
136392 KiB |
test_28.txt |
AC |
453 ms |
145872 KiB |
test_29.txt |
AC |
363 ms |
137520 KiB |
test_30.txt |
AC |
370 ms |
135868 KiB |
test_31.txt |
AC |
354 ms |
137356 KiB |
test_32.txt |
AC |
459 ms |
146132 KiB |
test_33.txt |
AC |
318 ms |
136376 KiB |
test_34.txt |
AC |
475 ms |
144964 KiB |
test_35.txt |
AC |
357 ms |
135500 KiB |
test_36.txt |
AC |
489 ms |
139632 KiB |
test_37.txt |
AC |
350 ms |
136444 KiB |
test_38.txt |
AC |
477 ms |
145696 KiB |
test_39.txt |
AC |
280 ms |
139964 KiB |
test_40.txt |
AC |
304 ms |
130868 KiB |
test_41.txt |
AC |
350 ms |
137456 KiB |
test_42.txt |
AC |
480 ms |
145876 KiB |
test_43.txt |
AC |
318 ms |
136628 KiB |
test_44.txt |
AC |
454 ms |
145528 KiB |
test_45.txt |
AC |
253 ms |
130476 KiB |
test_46.txt |
AC |
478 ms |
140480 KiB |
test_47.txt |
AC |
257 ms |
130604 KiB |
test_48.txt |
AC |
271 ms |
130732 KiB |
test_49.txt |
AC |
309 ms |
144912 KiB |
test_50.txt |
AC |
409 ms |
172548 KiB |