結果

問題 No.1170 Never Want to Walk
ユーザー shotoyooshotoyoo
提出日時 2020-08-14 22:01:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 1,637 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 113,608 KB
最終ジャッジ日時 2024-04-18 21:48:36
合計ジャッジ時間 7,892 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,096 KB
testcase_01 AC 39 ms
52,096 KB
testcase_02 AC 35 ms
52,352 KB
testcase_03 AC 35 ms
52,224 KB
testcase_04 AC 35 ms
52,608 KB
testcase_05 AC 39 ms
52,480 KB
testcase_06 AC 37 ms
52,608 KB
testcase_07 AC 39 ms
52,096 KB
testcase_08 AC 36 ms
52,608 KB
testcase_09 AC 39 ms
52,224 KB
testcase_10 AC 37 ms
52,480 KB
testcase_11 AC 40 ms
52,608 KB
testcase_12 AC 54 ms
63,360 KB
testcase_13 AC 68 ms
67,456 KB
testcase_14 AC 61 ms
67,712 KB
testcase_15 AC 56 ms
63,616 KB
testcase_16 AC 55 ms
64,768 KB
testcase_17 AC 63 ms
68,352 KB
testcase_18 AC 60 ms
63,488 KB
testcase_19 AC 66 ms
65,536 KB
testcase_20 AC 75 ms
73,984 KB
testcase_21 AC 59 ms
64,128 KB
testcase_22 AC 66 ms
70,528 KB
testcase_23 AC 77 ms
74,112 KB
testcase_24 AC 73 ms
72,960 KB
testcase_25 AC 64 ms
70,912 KB
testcase_26 AC 84 ms
74,752 KB
testcase_27 AC 397 ms
112,956 KB
testcase_28 AC 375 ms
112,252 KB
testcase_29 AC 403 ms
112,680 KB
testcase_30 AC 407 ms
112,652 KB
testcase_31 AC 405 ms
113,112 KB
testcase_32 AC 295 ms
112,296 KB
testcase_33 AC 314 ms
112,516 KB
testcase_34 AC 304 ms
113,128 KB
testcase_35 AC 356 ms
112,688 KB
testcase_36 AC 341 ms
112,216 KB
testcase_37 AC 301 ms
113,268 KB
testcase_38 AC 297 ms
113,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,a,b = list(map(int, input().split()))
xs = list(map(int, input().split()))
ls = [None]*n
rs = [None]*n
j = 0
for i in range(n):
    x = xs[i]
    while j+1<n and xs[j]<x+a:
        j += 1
    if x+a<=xs[j]<=x+b:
        ls[i] = j
j = 0
for i in range(n):
    x = xs[i]
    while j+1<n and xs[j+1]<=x+b:
        j += 1
    if x+a<=xs[j]<=x+b:
        rs[i] = j
        
        
class UnionFindTree:
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.size = [1] * n

    def root(self, i):
        inter = set()
        while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
        r = i
        for i in inter:
            self.parent[i] = r
        return r

    def connect(self, i, j):
        if i==j:
            return
        ri = self.root(i)
        rj = self.root(j)
        if ri==rj:
            return
        if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]
uf = UnionFindTree(n)
pl, pr = -1, -1
for i, (l,r) in enumerate(zip(ls,rs)):
    if l is not None and (l<=pr):
        uf.connect(i, i-1)
        for j in range(pr, r+1):
            uf.connect(i, j)
    elif l is not None:
        for j in range(l, r+1):
            uf.connect(i, j)
    else:
        pass
    if l is not None:
        pl,pr = l,r
for i in range(n):
    print(uf.size[uf.root(i)])
0