結果

問題 No.1170 Never Want to Walk
ユーザー roarisroaris
提出日時 2020-08-15 16:08:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 475 ms / 2,000 ms
コード長 1,425 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 105,304 KB
最終ジャッジ日時 2024-04-19 01:21:01
合計ジャッジ時間 9,429 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,096 KB
testcase_01 AC 41 ms
52,352 KB
testcase_02 AC 40 ms
52,480 KB
testcase_03 AC 40 ms
52,352 KB
testcase_04 AC 41 ms
52,352 KB
testcase_05 AC 47 ms
52,480 KB
testcase_06 AC 41 ms
52,096 KB
testcase_07 AC 41 ms
52,480 KB
testcase_08 AC 42 ms
52,608 KB
testcase_09 AC 41 ms
52,480 KB
testcase_10 AC 40 ms
52,224 KB
testcase_11 AC 41 ms
52,608 KB
testcase_12 AC 68 ms
66,944 KB
testcase_13 AC 74 ms
69,376 KB
testcase_14 AC 76 ms
69,632 KB
testcase_15 AC 69 ms
67,072 KB
testcase_16 AC 71 ms
67,840 KB
testcase_17 AC 78 ms
70,400 KB
testcase_18 AC 67 ms
66,048 KB
testcase_19 AC 73 ms
68,096 KB
testcase_20 AC 76 ms
69,888 KB
testcase_21 AC 68 ms
66,816 KB
testcase_22 AC 79 ms
71,168 KB
testcase_23 AC 78 ms
71,040 KB
testcase_24 AC 77 ms
70,528 KB
testcase_25 AC 79 ms
71,424 KB
testcase_26 AC 81 ms
72,320 KB
testcase_27 AC 432 ms
104,692 KB
testcase_28 AC 435 ms
104,728 KB
testcase_29 AC 442 ms
105,228 KB
testcase_30 AC 439 ms
105,136 KB
testcase_31 AC 431 ms
104,660 KB
testcase_32 AC 470 ms
104,592 KB
testcase_33 AC 475 ms
104,668 KB
testcase_34 AC 461 ms
105,232 KB
testcase_35 AC 425 ms
105,304 KB
testcase_36 AC 413 ms
104,520 KB
testcase_37 AC 414 ms
104,800 KB
testcase_38 AC 467 ms
105,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from bisect import *

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        r = x
        
        while not self.par[r]<0:
            r = self.par[r]
        
        t = x
        
        while t!=r:
            tmp = t
            t = self.par[t]
            self.par[tmp] = r
        
        return r
    
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        
        if rx==ry:
            return
        
        if self.rank[rx]<=self.rank[ry]:
            self.par[ry] += self.par[rx]
            self.par[rx] = ry
            
            if self.rank[rx]==self.rank[ry]:
                self.rank[ry] += 1
        else:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N, A, B = map(int, input().split())
x = list(map(int, input().split()))
uf = Unionfind(N)
imos = [0]*N

for i in range(N):
    l = bisect_left(x, x[i]+A)
    r = bisect_right(x, x[i]+B)-1
    
    if l<=r:
        uf.unite(i, l)
        imos[l] += 1
        imos[r] -= 1

for i in range(1, N):
    imos[i] += imos[i-1]

for i in range(N-1):
    if imos[i]>0:
        uf.unite(i, i+1)

for i in range(N):
    print(uf.count(i))
0