結果

問題 No.1170 Never Want to Walk
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-10-08 14:32:04
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,783 bytes
コンパイル時間 1,128 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 631,828 KB
最終ジャッジ日時 2023-09-04 19:47:06
合計ジャッジ時間 21,339 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
72,736 KB
testcase_01 AC 108 ms
72,684 KB
testcase_02 AC 106 ms
72,812 KB
testcase_03 AC 106 ms
72,772 KB
testcase_04 AC 106 ms
72,588 KB
testcase_05 AC 107 ms
72,644 KB
testcase_06 AC 107 ms
72,648 KB
testcase_07 AC 108 ms
72,620 KB
testcase_08 AC 107 ms
72,640 KB
testcase_09 AC 106 ms
72,704 KB
testcase_10 AC 109 ms
72,612 KB
testcase_11 AC 107 ms
72,692 KB
testcase_12 AC 165 ms
81,076 KB
testcase_13 AC 166 ms
80,864 KB
testcase_14 AC 165 ms
80,896 KB
testcase_15 AC 165 ms
80,916 KB
testcase_16 AC 170 ms
80,852 KB
testcase_17 AC 170 ms
81,040 KB
testcase_18 AC 165 ms
81,428 KB
testcase_19 AC 167 ms
80,804 KB
testcase_20 AC 166 ms
80,980 KB
testcase_21 AC 166 ms
81,188 KB
testcase_22 AC 179 ms
80,928 KB
testcase_23 AC 184 ms
81,032 KB
testcase_24 AC 188 ms
80,764 KB
testcase_25 AC 180 ms
80,844 KB
testcase_26 AC 184 ms
81,424 KB
testcase_27 AC 1,602 ms
347,648 KB
testcase_28 AC 1,364 ms
348,056 KB
testcase_29 AC 1,290 ms
346,804 KB
testcase_30 AC 1,495 ms
351,040 KB
testcase_31 AC 1,260 ms
346,208 KB
testcase_32 TLE -
testcase_33 MLE -
testcase_34 TLE -
testcase_35 MLE -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
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