結果

問題 No.1170 Never Want to Walk
ユーザー uni_pythonuni_python
提出日時 2020-08-15 20:25:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 391 ms / 2,000 ms
コード長 3,088 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 82,236 KB
実行使用メモリ 103,888 KB
最終ジャッジ日時 2024-04-19 06:02:13
合計ジャッジ時間 7,846 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,308 KB
testcase_01 AC 39 ms
53,216 KB
testcase_02 AC 39 ms
54,024 KB
testcase_03 AC 42 ms
54,204 KB
testcase_04 AC 40 ms
54,288 KB
testcase_05 AC 39 ms
54,520 KB
testcase_06 AC 39 ms
54,416 KB
testcase_07 AC 37 ms
53,076 KB
testcase_08 AC 39 ms
53,552 KB
testcase_09 AC 39 ms
53,752 KB
testcase_10 AC 38 ms
53,108 KB
testcase_11 AC 38 ms
53,228 KB
testcase_12 AC 59 ms
68,588 KB
testcase_13 AC 63 ms
70,996 KB
testcase_14 AC 63 ms
69,632 KB
testcase_15 AC 59 ms
68,204 KB
testcase_16 AC 62 ms
68,764 KB
testcase_17 AC 63 ms
69,460 KB
testcase_18 AC 60 ms
68,844 KB
testcase_19 AC 62 ms
68,644 KB
testcase_20 AC 62 ms
69,632 KB
testcase_21 AC 61 ms
69,012 KB
testcase_22 AC 62 ms
70,004 KB
testcase_23 AC 65 ms
71,744 KB
testcase_24 AC 61 ms
69,768 KB
testcase_25 AC 64 ms
69,692 KB
testcase_26 AC 64 ms
72,084 KB
testcase_27 AC 367 ms
102,804 KB
testcase_28 AC 365 ms
103,504 KB
testcase_29 AC 391 ms
103,764 KB
testcase_30 AC 370 ms
103,096 KB
testcase_31 AC 370 ms
103,140 KB
testcase_32 AC 372 ms
103,356 KB
testcase_33 AC 369 ms
102,516 KB
testcase_34 AC 368 ms
103,888 KB
testcase_35 AC 346 ms
103,488 KB
testcase_36 AC 327 ms
102,928 KB
testcase_37 AC 317 ms
103,312 KB
testcase_38 AC 353 ms
103,304 KB
権限があれば一括ダウンロードができます

ソースコード

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)に辺を張る,これはimos風にやる
    """


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

                

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

    
    


main()
0