結果

問題 No.1170 Never Want to Walk
ユーザー roarisroaris
提出日時 2020-08-15 16:08:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 469 ms / 2,000 ms
コード長 1,425 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 105,232 KB
最終ジャッジ日時 2024-10-10 18:03:43
合計ジャッジ時間 9,491 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,096 KB
testcase_01 AC 42 ms
52,224 KB
testcase_02 AC 43 ms
51,840 KB
testcase_03 AC 42 ms
52,096 KB
testcase_04 AC 41 ms
52,096 KB
testcase_05 AC 42 ms
52,224 KB
testcase_06 AC 42 ms
51,840 KB
testcase_07 AC 42 ms
52,096 KB
testcase_08 AC 43 ms
52,096 KB
testcase_09 AC 42 ms
52,096 KB
testcase_10 AC 43 ms
52,096 KB
testcase_11 AC 42 ms
52,224 KB
testcase_12 AC 69 ms
66,304 KB
testcase_13 AC 76 ms
68,992 KB
testcase_14 AC 77 ms
69,376 KB
testcase_15 AC 70 ms
67,072 KB
testcase_16 AC 73 ms
67,840 KB
testcase_17 AC 78 ms
69,504 KB
testcase_18 AC 69 ms
66,176 KB
testcase_19 AC 73 ms
68,224 KB
testcase_20 AC 76 ms
69,888 KB
testcase_21 AC 71 ms
66,304 KB
testcase_22 AC 78 ms
70,912 KB
testcase_23 AC 79 ms
70,528 KB
testcase_24 AC 79 ms
70,784 KB
testcase_25 AC 79 ms
70,784 KB
testcase_26 AC 82 ms
71,936 KB
testcase_27 AC 438 ms
104,252 KB
testcase_28 AC 438 ms
104,556 KB
testcase_29 AC 447 ms
105,232 KB
testcase_30 AC 439 ms
104,368 KB
testcase_31 AC 436 ms
104,536 KB
testcase_32 AC 464 ms
104,716 KB
testcase_33 AC 465 ms
104,292 KB
testcase_34 AC 469 ms
105,108 KB
testcase_35 AC 429 ms
104,788 KB
testcase_36 AC 412 ms
104,256 KB
testcase_37 AC 395 ms
104,416 KB
testcase_38 AC 452 ms
105,180 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