結果

問題 No.1170 Never Want to Walk
ユーザー terasaterasa
提出日時 2022-05-24 11:45:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 820 ms / 2,000 ms
コード長 2,349 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 107,228 KB
最終ジャッジ日時 2024-09-20 13:35:14
合計ジャッジ時間 13,380 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,408 KB
testcase_01 AC 45 ms
55,400 KB
testcase_02 AC 43 ms
55,844 KB
testcase_03 AC 42 ms
56,136 KB
testcase_04 AC 43 ms
56,052 KB
testcase_05 AC 45 ms
56,500 KB
testcase_06 AC 43 ms
56,316 KB
testcase_07 AC 42 ms
55,524 KB
testcase_08 AC 44 ms
56,488 KB
testcase_09 AC 43 ms
55,736 KB
testcase_10 AC 43 ms
56,016 KB
testcase_11 AC 44 ms
55,488 KB
testcase_12 AC 67 ms
71,092 KB
testcase_13 AC 75 ms
76,676 KB
testcase_14 AC 75 ms
76,464 KB
testcase_15 AC 67 ms
72,352 KB
testcase_16 AC 71 ms
73,856 KB
testcase_17 AC 75 ms
76,408 KB
testcase_18 AC 65 ms
71,916 KB
testcase_19 AC 68 ms
73,304 KB
testcase_20 AC 75 ms
76,040 KB
testcase_21 AC 67 ms
72,044 KB
testcase_22 AC 76 ms
76,732 KB
testcase_23 AC 77 ms
75,988 KB
testcase_24 AC 75 ms
76,372 KB
testcase_25 AC 79 ms
76,440 KB
testcase_26 AC 79 ms
76,060 KB
testcase_27 AC 788 ms
106,500 KB
testcase_28 AC 792 ms
104,648 KB
testcase_29 AC 745 ms
107,228 KB
testcase_30 AC 785 ms
106,968 KB
testcase_31 AC 792 ms
104,852 KB
testcase_32 AC 796 ms
106,492 KB
testcase_33 AC 794 ms
104,452 KB
testcase_34 AC 802 ms
106,804 KB
testcase_35 AC 820 ms
106,824 KB
testcase_36 AC 788 ms
105,140 KB
testcase_37 AC 725 ms
104,784 KB
testcase_38 AC 752 ms
106,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import pypyjit
import itertools
import heapq
import math
from collections import deque, defaultdict, Counter
import bisect

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
pypyjit.set_param('max_unroll_recursion=-1')


class UnionFind:
    def __init__(self, N):
        self.N = N
        self.par = [-1] * N
        self.l = [i for i in range(N)]
        self.r = [i for i in range(N)]

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def left(self, x):
        return self.l[self.find(x)]

    def right(self, x):
        return self.r[self.find(x)]

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

        if x == y:
            return False
        if x > y:
            x, y = y, x

        self.par[x] += self.par[y]
        self.l[x] = min(self.l[x], self.l[y])
        self.r[x] = max(self.r[x], self.r[y])
        self.par[y] = x
        return True

    def unite_range(self, x, y):
        if x > y:
            return
        while self.right(x) < y:
            self.unite(self.right(x), self.right(x) + 1)

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

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

    def roots(self):
        return [i for i in range(self.N) if self.par[i] < 0]

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


def index_lt(a, x):
    'return largest index s.t. A[i] < x or -1 if it does not exist'
    return bisect.bisect_left(a, x) - 1


def index_le(a, x):
    'return largest index s.t. A[i] <= x or -1 if it does not exist'
    return bisect.bisect_right(a, x) - 1


def index_gt(a, x):
    'return smallest index s.t. A[i] > x or len(a) if it does not exist'
    return bisect.bisect_right(a, x)


def index_ge(a, x):
    'return smallest index s.t. A[i] >= x or len(a) if it does not exist'
    return bisect.bisect_left(a, x)


N, A, B = map(int, input().split())
X = list(map(int, input().split()))
uf = UnionFind(N)
cnt = N
for i, x in enumerate(X):
    a = index_ge(X, x + A)
    b = index_le(X, x + B)
    if a > b:
        continue
    uf.unite_range(a, b)
    uf.unite(i, a)
for i in range(N):
    print(uf.size(i))
0