結果
問題 | No.1170 Never Want to Walk |
ユーザー |
![]() |
提出日時 | 2022-04-19 18:59:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 369 ms / 2,000 ms |
コード長 | 1,321 bytes |
コンパイル時間 | 222 ms |
コンパイル使用メモリ | 82,516 KB |
実行使用メモリ | 104,240 KB |
最終ジャッジ日時 | 2025-01-02 10:28:48 |
合計ジャッジ時間 | 8,723 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 37 |
ソースコード
import bisect#UnionFindfrom collections import defaultdictclass UnionFind():def __init__(self, n):self.n = nself.parents = [-1] * ndef find(self, x):if self.parents[x] < 0:return xelse:self.parents[x] = self.find(self.parents[x])return self.parents[x]def union(self, x, y):x = self.find(x)y = self.find(y)if x == y:returnif self.parents[x] > self.parents[y]:x, y = y, xself.parents[x] += self.parents[y]self.parents[y] = xdef size(self, x):return -self.parents[self.find(x)]def same(self, x, y):return self.find(x) == self.find(y)def members(self, x):root = self.find(x)return [i for i in range(self.n) if self.find(i) == root]def roots(self):return [i for i, x in enumerate(self.parents) if x < 0]n,a,b=map(int,input().split())x=list(map(int,input().split()))unite=[0]*nuf=UnionFind(n)for i in range(n):L=bisect.bisect_left(x,x[i]+a)R=bisect.bisect_left(x,x[i]+b+1)if L!=R:uf.union(i,L)unite[L]+=1unite[R-1]-=1for i in range(n-1):if i:unite[i]+=unite[i-1]if unite[i]:uf.union(i,i+1)for i in range(n):print(uf.size(i))