結果

問題 No.1170 Never Want to Walk
ユーザー tyawanmusityawanmusi
提出日時 2020-08-14 23:04:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,725 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 109,144 KB
最終ジャッジ日時 2024-04-18 22:56:07
合計ジャッジ時間 14,317 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
18,076 KB
testcase_01 AC 30 ms
11,136 KB
testcase_02 AC 30 ms
11,136 KB
testcase_03 AC 31 ms
11,008 KB
testcase_04 AC 31 ms
11,136 KB
testcase_05 AC 30 ms
11,008 KB
testcase_06 AC 30 ms
11,008 KB
testcase_07 AC 31 ms
11,136 KB
testcase_08 AC 29 ms
11,136 KB
testcase_09 AC 28 ms
11,008 KB
testcase_10 AC 29 ms
11,136 KB
testcase_11 AC 26 ms
11,136 KB
testcase_12 AC 33 ms
11,264 KB
testcase_13 AC 35 ms
11,264 KB
testcase_14 AC 34 ms
11,264 KB
testcase_15 AC 34 ms
11,392 KB
testcase_16 AC 36 ms
11,392 KB
testcase_17 AC 37 ms
11,264 KB
testcase_18 AC 36 ms
11,392 KB
testcase_19 AC 36 ms
11,264 KB
testcase_20 AC 38 ms
11,392 KB
testcase_21 AC 35 ms
11,392 KB
testcase_22 AC 45 ms
11,392 KB
testcase_23 AC 45 ms
11,264 KB
testcase_24 AC 45 ms
11,264 KB
testcase_25 AC 44 ms
11,392 KB
testcase_26 AC 44 ms
11,264 KB
testcase_27 AC 1,707 ms
71,836 KB
testcase_28 AC 1,756 ms
71,780 KB
testcase_29 AC 1,696 ms
71,588 KB
testcase_30 AC 1,769 ms
72,188 KB
testcase_31 AC 1,697 ms
71,500 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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