結果

問題 No.1170 Never Want to Walk
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-10-08 14:31:25
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,723 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 86,732 KB
実行使用メモリ 631,340 KB
最終ジャッジ日時 2023-09-04 19:45:40
合計ジャッジ時間 22,662 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
72,656 KB
testcase_01 AC 105 ms
72,572 KB
testcase_02 AC 105 ms
72,624 KB
testcase_03 AC 105 ms
72,676 KB
testcase_04 AC 105 ms
72,672 KB
testcase_05 AC 106 ms
72,576 KB
testcase_06 AC 104 ms
72,816 KB
testcase_07 AC 109 ms
72,732 KB
testcase_08 AC 105 ms
72,496 KB
testcase_09 AC 106 ms
72,296 KB
testcase_10 AC 107 ms
72,624 KB
testcase_11 AC 105 ms
72,776 KB
testcase_12 AC 159 ms
80,944 KB
testcase_13 AC 159 ms
81,028 KB
testcase_14 AC 162 ms
80,996 KB
testcase_15 AC 160 ms
81,264 KB
testcase_16 AC 170 ms
81,228 KB
testcase_17 AC 183 ms
81,216 KB
testcase_18 AC 164 ms
80,988 KB
testcase_19 AC 159 ms
80,840 KB
testcase_20 AC 167 ms
81,480 KB
testcase_21 AC 159 ms
80,996 KB
testcase_22 AC 181 ms
81,132 KB
testcase_23 AC 181 ms
81,192 KB
testcase_24 AC 179 ms
81,152 KB
testcase_25 AC 175 ms
80,920 KB
testcase_26 AC 184 ms
81,272 KB
testcase_27 AC 1,513 ms
348,212 KB
testcase_28 AC 1,318 ms
347,964 KB
testcase_29 AC 1,308 ms
347,732 KB
testcase_30 AC 1,419 ms
349,596 KB
testcase_31 AC 1,355 ms
346,024 KB
testcase_32 TLE -
testcase_33 MLE -
testcase_34 TLE -
testcase_35 MLE -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N,A,B = map(int,input().split())
X = list(map(int,input().split()))
Q = 2*N
# 頂点数N,追加エッジの個数Q
# 頂点iのインデックスはn+iになる(エッジを追加するときは気にする必要はない)
n = 1
while n < N:
    n *= 2
N3 = 3*n + 1
e = [[] for _ in range(N3+2*Q)]
for i in range(n-1,0,-1):
    
    a = 2*i
    b = 2*i+1
    e[i].append((a,0))
    e[i].append((b,0))
    if n<=a<2*n:
        e[a].append((i+2*n,0))
    else:
        e[a+2*n].append((i+2*n,0))
        
        
    if n<=b<2*n:
        e[b].append((i+2*n,0))
    else:
        e[b+2*n].append((i+2*n,0))

q = 0
def add(l1,r1,l2,r2,c):
    ##[l1,r1)から[l2,r2)にコストcの辺を張る
    global q,e
    source = []
    l1 += n
    r1 += n
    while l1<r1:
        if l1&1:
            if n<=l1<2*n:
                source.append(l1)
            else:
                source.append(l1+2*n)
            l1 += 1
        if r1&1:
            if n<=r1-1<2*n:
                source.append(r1-1)
            else:
                source.append(r1+2*n-1)
        l1 >>= 1
        r1 >>= 1
    
    target = []
    l2 += n
    r2 += n
    while l2<r2:
        if l2&1:
            target.append(l2)
            l2 += 1
        if r2&1:
            target.append(r2-1)
        l2 >>= 1
        r2 >>= 1
    
    for s in source:
        e[s].append((N3+q,0))
    for t in target:
        e[N3+q+1].append((t,0))
    
    e[N3+q].append((N3+q+1,c))
    q += 2
    return
        
for i in range(N):
    
    xi = X[i]
    l = N
    ng = i
    while l-ng>1:
        
        mid = (l+ng)//2
        
        if X[mid]>=A+xi:
            
            l = mid
        else:
            
            ng = mid
            
            
    r = i
    ng = N
    while ng-r>1:
        mid = (ng+r)//2
        
        if X[mid]<=xi+B:
            r = mid
        else:
            ng = mid
    r += 1
    add(i,i+1,l,r,1)
    add(l,r,i,i+1,1)
            

        
visited = [False]*(N3+2*Q)
ans = [1]*(N3+2*Q)

for i in range(N):
    
    if visited[i+n]:
        continue
    
    visited[i+n]=True
    v = deque()
    v.append(i+n)
    target = deque()
    target.append(i+n)
    cnt = 1
    while v:
        
        x = v.popleft()
        
        for ix,_ in e[x]:
            
            if visited[ix]:
                continue
            visited[ix] = True
            if n<=ix<n+N:
                cnt += 1
                target.append(ix)
            v.append(ix)
    
    while target:
        y = target.pop()
        ans[y] = cnt
        
        
print(*ans[n:n+N],sep='\n')
0