結果

問題 No.1170 Never Want to Walk
ユーザー Kiri8128Kiri8128
提出日時 2020-08-16 18:09:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,655 ms / 2,000 ms
コード長 2,044 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 82,144 KB
実行使用メモリ 464,408 KB
最終ジャッジ日時 2024-04-19 18:27:36
合計ジャッジ時間 19,726 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,272 KB
testcase_01 AC 40 ms
54,400 KB
testcase_02 AC 38 ms
54,252 KB
testcase_03 AC 36 ms
54,424 KB
testcase_04 AC 36 ms
54,616 KB
testcase_05 AC 37 ms
54,528 KB
testcase_06 AC 42 ms
54,400 KB
testcase_07 AC 38 ms
54,400 KB
testcase_08 AC 37 ms
54,400 KB
testcase_09 AC 37 ms
54,144 KB
testcase_10 AC 36 ms
54,656 KB
testcase_11 AC 37 ms
54,016 KB
testcase_12 AC 76 ms
77,440 KB
testcase_13 AC 74 ms
77,484 KB
testcase_14 AC 81 ms
77,184 KB
testcase_15 AC 76 ms
77,440 KB
testcase_16 AC 76 ms
77,312 KB
testcase_17 AC 84 ms
77,408 KB
testcase_18 AC 78 ms
77,244 KB
testcase_19 AC 76 ms
77,184 KB
testcase_20 AC 85 ms
77,528 KB
testcase_21 AC 77 ms
77,356 KB
testcase_22 AC 95 ms
77,504 KB
testcase_23 AC 102 ms
77,552 KB
testcase_24 AC 98 ms
77,340 KB
testcase_25 AC 100 ms
77,332 KB
testcase_26 AC 94 ms
77,536 KB
testcase_27 AC 1,103 ms
318,328 KB
testcase_28 AC 1,123 ms
291,292 KB
testcase_29 AC 1,038 ms
278,276 KB
testcase_30 AC 1,090 ms
281,640 KB
testcase_31 AC 1,106 ms
307,056 KB
testcase_32 AC 1,475 ms
451,480 KB
testcase_33 AC 1,655 ms
433,216 KB
testcase_34 AC 1,482 ms
446,344 KB
testcase_35 AC 1,643 ms
460,668 KB
testcase_36 AC 1,392 ms
455,320 KB
testcase_37 AC 1,427 ms
458,800 KB
testcase_38 AC 1,487 ms
464,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_right as br
from collections import deque

class range_edge:
    def __init__(self, n):
        self.k = (n-1).bit_length()
        self.K = 1 << self.k
        self.KK = self.K * 3
        self.E = [[] for _ in range(self.KK)]
        for i in range(2, self.K * 2):
            self.E[i >> 1].append(i)
        for i in range(self.K, self.KK - 2):
            self.E[i].append(i + self.KK >> 1)
        self.c = self.KK # Number of Vertices
    
    def add_range_edge(self, a, b, c, d): # from [a, b) to [c, d)
        if a >= b or c >= d: return
        E = self.E
        K = self.K
        KK = K * 3
        a -= K * 2
        b -= K * 2
        while a < b:
            if a & 1:
                E[a + KK].append(self.c)
                a += 1
            a >>= 1
            if b & 1:
                b -= 1
                self.E[b + KK].append(self.c)
            b >>= 1
        self.c += 1
        E.append([self.c]) # cost = 0
        E.append([])
        
        c += K
        d += K
        while c < d:
            if c & 1:
                E[self.c].append(c)
                c += 1
            c >>= 1
            if d & 1:
                d -= 1
                E[self.c].append(d)
            d >>= 1
        self.c += 1
    
    def BFS0(self, i0=0):
        E = self.E
        K = self.K
        i0 += K
        Q = deque([i0])
        n = self.c
        done = {i0}
        while Q:
            i = Q.popleft()
            for j in E[i]:
                if j not in done:
                    done.add(j)
                    Q.append(j)
        return [a - K for a in done if K <= a < 2 * K]

N, A, B = map(int, input().split())
re = range_edge(N)
X = [int(a) for a in input().split()]
for i in range(N):
    l = br(X, X[i] + A - 1)
    r = br(X, X[i] + B)
    re.add_range_edge(i, i + 1, l, r)
    re.add_range_edge(l, r, i, i + 1)

ANS = [0] * N
for i in range(N):
    if ANS[i]: continue
    bfs = re.BFS0(i)
    ans = len(bfs)
    for j in bfs:
        ANS[j] = ans
print(*ANS, sep = "\n")
0