結果

問題 No.1170 Never Want to Walk
ユーザー uni_pythonuni_python
提出日時 2020-08-15 12:36:15
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 3,113 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 87,260 KB
実行使用メモリ 108,420 KB
最終ジャッジ日時 2023-08-01 01:15:03
合計ジャッジ時間 10,372 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
76,044 KB
testcase_01 AC 68 ms
71,340 KB
testcase_02 AC 68 ms
71,292 KB
testcase_03 AC 69 ms
71,572 KB
testcase_04 AC 69 ms
71,592 KB
testcase_05 AC 69 ms
71,436 KB
testcase_06 AC 70 ms
71,524 KB
testcase_07 AC 69 ms
71,564 KB
testcase_08 AC 70 ms
71,296 KB
testcase_09 AC 67 ms
71,272 KB
testcase_10 AC 69 ms
71,276 KB
testcase_11 AC 69 ms
71,332 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 104 ms
77,868 KB
testcase_23 AC 123 ms
77,532 KB
testcase_24 AC 98 ms
77,144 KB
testcase_25 AC 107 ms
77,492 KB
testcase_26 AC 118 ms
78,028 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 252 ms
104,820 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    ################
    class UnionFind():
        """
        parents : 親要素(findしない場合は根ではないことの注意),根の場合は"-(要素数)"
        find(x):要素xの属するグループの根を返す
        size(x):要素xの属するグループの要素数を返す
        same(x,y):x,yが同じグループに属しているか返す
        重いかも!  members(x):要素xが属するグループに属する要素をリストで返す
        roots:全ての根の要素を返す
        group_count():グループの数を返す
        重いかも! all_group_members():{根要素:[そのグループに含まれる要素のリスト]}の辞書を返す
        """
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            #根を探す&つなぎかえる
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    ################
    """
    i番目からa~bまでそれぞれ編を貼ると大変
    (i,a),(a,a+1),...,(b-1,b)に辺を張るか,連番のやつはどこまで辺を貼ったか覚えておき,2回目はやらない
    """


    import bisect
    
    mod=10**9+7
    N,A,B=MI()
    x=LI()
    uf=UnionFind(N)
    
    L=[-1]*N#連番でどこまで繋いだか
    for i in range(N):
        
        nl=bisect.bisect_left(x,x[i]+A)
        nr=bisect.bisect_right(x,x[i]+B)
        # print(i,nl,nr)
        if nl<N:
            if nl!=nr:
                uf.union(i,nl)
                
                if L[nl]!=-1:
                    nl=L[nl]
                
                for j in range(nl,nr-1):
                    uf.union(j,j+1)
                    L[j]=nr
                

    for i in range(N):
        print(uf.size(i))
            
            
            
    

    
    


main()
0