結果

問題 No.1170 Never Want to Walk
ユーザー anagohirameanagohirame
提出日時 2020-08-14 22:14:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,163 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 104,352 KB
最終ジャッジ日時 2024-04-18 22:04:18
合計ジャッジ時間 9,115 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,480 KB
testcase_01 AC 37 ms
52,608 KB
testcase_02 AC 38 ms
52,864 KB
testcase_03 AC 38 ms
52,480 KB
testcase_04 AC 38 ms
52,992 KB
testcase_05 AC 37 ms
52,480 KB
testcase_06 AC 37 ms
52,864 KB
testcase_07 AC 38 ms
52,480 KB
testcase_08 AC 38 ms
52,608 KB
testcase_09 AC 36 ms
52,352 KB
testcase_10 AC 37 ms
52,096 KB
testcase_11 AC 35 ms
52,864 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 74 ms
72,832 KB
testcase_23 AC 69 ms
74,052 KB
testcase_24 AC 68 ms
73,216 KB
testcase_25 AC 66 ms
72,684 KB
testcase_26 AC 74 ms
75,588 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 414 ms
103,828 KB
testcase_33 AC 478 ms
103,228 KB
testcase_34 AC 472 ms
103,836 KB
testcase_35 AC 415 ms
103,604 KB
testcase_36 AC 379 ms
102,984 KB
testcase_37 AC 452 ms
103,280 KB
testcase_38 AC 428 ms
103,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect, bisect_left
import sys
def input():
	return sys.stdin.readline()[:-1]

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]
		self.size = [1 for _ in range(size)]

	def find(self, x):
		while self.table[x] >= 0:
			if self.table[self.table[x]] >= 0:
				self.table[x] = self.table[self.table[x]]
			x = self.table[x]
		return x

	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 == s2:
			return False
		else:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
				self.table[s1] -= 1
				self.size[s1] += self.size[s2]
				self.size[s2] = 0
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
				self.size[s2] += self.size[s1]
				self.size[s1] = 0
			return True

	def get_size(self, x):
		return self.size[self.find(x)]

n, a, b = map(int, input().split())
x = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(n):
	l = bisect_left(x, x[i]+a)
	r = bisect(x, x[i]+b)
	#print(l, r)
	if l == r:
		continue
	if l == n:
		break
	uf.unite(i, l)
	j = l
	while j < r-1 and uf.unite(j, j+1):
		j += 1
print(*[uf.get_size(i) for i in range(n)], sep="\n")
0