結果

問題 No.1170 Never Want to Walk
ユーザー tyawanmusityawanmusi
提出日時 2020-08-14 23:04:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 809 ms / 2,000 ms
コード長 1,725 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 268,036 KB
最終ジャッジ日時 2024-04-18 22:56:59
合計ジャッジ時間 12,746 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,352 KB
testcase_01 AC 41 ms
52,352 KB
testcase_02 AC 42 ms
52,992 KB
testcase_03 AC 38 ms
52,608 KB
testcase_04 AC 38 ms
52,864 KB
testcase_05 AC 38 ms
52,608 KB
testcase_06 AC 37 ms
53,248 KB
testcase_07 AC 37 ms
52,812 KB
testcase_08 AC 37 ms
52,608 KB
testcase_09 AC 36 ms
53,248 KB
testcase_10 AC 37 ms
52,352 KB
testcase_11 AC 38 ms
52,992 KB
testcase_12 AC 69 ms
74,600 KB
testcase_13 AC 78 ms
76,416 KB
testcase_14 AC 76 ms
75,964 KB
testcase_15 AC 70 ms
72,960 KB
testcase_16 AC 73 ms
74,240 KB
testcase_17 AC 80 ms
76,528 KB
testcase_18 AC 67 ms
71,680 KB
testcase_19 AC 72 ms
73,600 KB
testcase_20 AC 83 ms
76,672 KB
testcase_21 AC 69 ms
73,216 KB
testcase_22 AC 90 ms
76,672 KB
testcase_23 AC 96 ms
76,960 KB
testcase_24 AC 92 ms
76,840 KB
testcase_25 AC 108 ms
77,056 KB
testcase_26 AC 101 ms
77,056 KB
testcase_27 AC 711 ms
129,728 KB
testcase_28 AC 751 ms
129,588 KB
testcase_29 AC 746 ms
129,420 KB
testcase_30 AC 753 ms
130,116 KB
testcase_31 AC 736 ms
129,920 KB
testcase_32 AC 742 ms
247,080 KB
testcase_33 AC 809 ms
185,224 KB
testcase_34 AC 742 ms
217,340 KB
testcase_35 AC 760 ms
268,036 KB
testcase_36 AC 677 ms
241,688 KB
testcase_37 AC 784 ms
242,824 KB
testcase_38 AC 749 ms
202,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**9)
class UnionFind:
  def __init__(self, n):
    self.n = [-1]*n
    self.r = [0]*n
    self.siz = n

  def find_root(self, x):
    if self.n[x] < 0:
      return x
    else:
      self.n[x] = self.find_root(self.n[x])
      return self.n[x]

  def unite(self, x, y):
    x = self.find_root(x)
    y = self.find_root(y)
    if x == y:
      return
    elif self.r[x] > self.r[y]:
      self.n[x] += self.n[y]
      self.n[y] = x
    else:
      self.n[y] += self.n[x]
      self.n[x] = y
      if self.r[x] == self.r[y]:
        self.r[y] += 1
    self.siz -= 1

  def root_same(self, x, y):
    return self.find_root(x) == self.find_root(y)

  def count(self, x):
    return -self.n[self.find_root(x)]

  def size(self):
    return self.siz

n,a,b=map(int,input().split())
x=list(map(int,input().split()))
from bisect import bisect_left,bisect_right
num = 2**(n-1).bit_length()
edge=[[]for _ in range(2*num-1)]
def query(l, r, i):
  l += num-1
  r += num-1
  if l==r:
    edge[l].append(i)
    return
  l += 1
  while r-l > 1:
    if ~l % 2:
      edge[l].append(i)
    if r % 2:
      edge[r].append(i)
      r -= 1
    l //= 2
    r = (r-1)//2
  edge[l].append(i)
  if l == r:return 
  edge[r].append(i)

for i in range(n):
  if bisect_left(x,x[i]+a)==bisect_right(x,x[i]+b):continue
  query(bisect_left(x,x[i]+a)-1,bisect_right(x,x[i]+b)-1,i)

u=UnionFind(n)
ind=0
for i in range(num.bit_length()):
  v=num//(2**i)
  for j in range(0,num,v):
    if len(edge[ind])==0:
      ind+=1
      continue
    for k in range(len(edge[ind])-1):
      u.unite(edge[ind][k],edge[ind][k+1])
    for k in range(j,j+v):
      u.unite(edge[ind][0],k)
    ind+=1

for i in range(n):
  print(u.count(i))
0