結果

問題 No.1170 Never Want to Walk
ユーザー ayaoniayaoni
提出日時 2020-11-22 13:56:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 356 ms / 2,000 ms
コード長 1,727 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 112,568 KB
最終ジャッジ日時 2023-09-30 22:46:30
合計ジャッジ時間 10,288 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,296 KB
testcase_01 AC 71 ms
71,268 KB
testcase_02 AC 72 ms
71,476 KB
testcase_03 AC 72 ms
71,484 KB
testcase_04 AC 73 ms
71,396 KB
testcase_05 AC 72 ms
71,332 KB
testcase_06 AC 73 ms
71,692 KB
testcase_07 AC 72 ms
71,348 KB
testcase_08 AC 72 ms
71,332 KB
testcase_09 AC 73 ms
71,336 KB
testcase_10 AC 73 ms
71,568 KB
testcase_11 AC 73 ms
71,500 KB
testcase_12 AC 95 ms
76,548 KB
testcase_13 AC 101 ms
76,544 KB
testcase_14 AC 96 ms
76,584 KB
testcase_15 AC 94 ms
76,520 KB
testcase_16 AC 98 ms
76,592 KB
testcase_17 AC 104 ms
77,396 KB
testcase_18 AC 92 ms
76,672 KB
testcase_19 AC 95 ms
76,584 KB
testcase_20 AC 103 ms
77,428 KB
testcase_21 AC 96 ms
76,772 KB
testcase_22 AC 102 ms
77,312 KB
testcase_23 AC 103 ms
77,188 KB
testcase_24 AC 105 ms
77,144 KB
testcase_25 AC 104 ms
77,308 KB
testcase_26 AC 102 ms
77,276 KB
testcase_27 AC 335 ms
112,032 KB
testcase_28 AC 320 ms
111,764 KB
testcase_29 AC 356 ms
111,472 KB
testcase_30 AC 330 ms
112,352 KB
testcase_31 AC 329 ms
111,944 KB
testcase_32 AC 298 ms
110,192 KB
testcase_33 AC 292 ms
111,968 KB
testcase_34 AC 301 ms
111,712 KB
testcase_35 AC 309 ms
111,172 KB
testcase_36 AC 290 ms
111,992 KB
testcase_37 AC 289 ms
111,548 KB
testcase_38 AC 296 ms
112,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from bisect import bisect_left,bisect_right
from itertools import accumulate
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))


class UnionFind:
    def __init__(self,n):
        self.par = [i for i in range(n+1)]  # 親のノード番号
        self.rank = [0]*(n+1)
        self.C = [1]*(n+1)

    def find(self,x):  # xの根のノード番号
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self,x,y):  # x,yが同じグループか否か
        return self.find(x) == self.find(y)

    def unite(self,x,y):  # x,yの属するグループの併合
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            x,y = y,x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.par[y] = x
        self.C[x] += self.C[y]


N,A,B = MI()
X = [-1]+LI()
Y = [0]*(N+2)

UF = UnionFind(N+1)
for i in range(1,N+1):
    x = X[i]
    ng,ok = i,N+1
    while ng+1 < ok:
        mid = (ng+ok)//2
        if X[mid] >= x+A:
            ok = mid
        else:
            ng = mid
    left = ok
    ok,ng = i,N+1
    while ok+1 < ng:
        mid = (ok+ng)//2
        if X[mid] <= x+B:
            ok = mid
        else:
            ng = mid
    right = ok
    if left <= right:
        if not UF.same_check(i,left):
            UF.unite(i,left)
        Y[left] += 1
        Y[right] -= 1

Y = list(accumulate(Y))
for i in range(1,N+1):
    if Y[i] > 0 and not UF.same_check(i,i+1):
        UF.unite(i,i+1)

for i in range(1,N+1):
    print(UF.C[UF.find(i)])
0