結果
問題 | No.1170 Never Want to Walk |
ユーザー | ikd |
提出日時 | 2020-08-21 21:08:55 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 348 ms / 2,000 ms |
コード長 | 3,540 bytes |
コンパイル時間 | 17,377 ms |
コンパイル使用メモリ | 395,876 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-10-15 04:59:56 |
合計ジャッジ時間 | 22,702 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 1 ms
6,820 KB |
testcase_06 | AC | 1 ms
6,816 KB |
testcase_07 | AC | 1 ms
6,820 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,820 KB |
testcase_10 | AC | 1 ms
6,816 KB |
testcase_11 | AC | 1 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,816 KB |
testcase_13 | AC | 3 ms
6,816 KB |
testcase_14 | AC | 2 ms
6,816 KB |
testcase_15 | AC | 3 ms
6,820 KB |
testcase_16 | AC | 3 ms
6,816 KB |
testcase_17 | AC | 2 ms
6,816 KB |
testcase_18 | AC | 3 ms
6,820 KB |
testcase_19 | AC | 2 ms
6,816 KB |
testcase_20 | AC | 3 ms
6,820 KB |
testcase_21 | AC | 3 ms
6,816 KB |
testcase_22 | AC | 3 ms
6,816 KB |
testcase_23 | AC | 2 ms
6,820 KB |
testcase_24 | AC | 3 ms
6,820 KB |
testcase_25 | AC | 2 ms
6,820 KB |
testcase_26 | AC | 2 ms
6,816 KB |
testcase_27 | AC | 339 ms
7,168 KB |
testcase_28 | AC | 334 ms
7,040 KB |
testcase_29 | AC | 348 ms
7,168 KB |
testcase_30 | AC | 346 ms
7,168 KB |
testcase_31 | AC | 336 ms
6,912 KB |
testcase_32 | AC | 344 ms
7,168 KB |
testcase_33 | AC | 335 ms
7,040 KB |
testcase_34 | AC | 344 ms
7,296 KB |
testcase_35 | AC | 342 ms
7,040 KB |
testcase_36 | AC | 335 ms
7,040 KB |
testcase_37 | AC | 338 ms
7,168 KB |
testcase_38 | AC | 348 ms
7,168 KB |
ソースコード
use std::io::Read; fn read<T: std::str::FromStr>() -> T { let token: String = std::io::stdin() .bytes() .map(|c| c.ok().unwrap() as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().unwrap() } mod binary_search { use std::ops::Range; pub trait BinarySearch<T> { fn lower_bound(&self, x: &T) -> usize; fn upper_bound(&self, x: &T) -> usize; fn split_by(&self, x: &T) -> (Range<usize>, Range<usize>, Range<usize>); } // min index self[i] >= x // that is, any j (j < i) holds self[j] < x impl<T: Ord> BinarySearch<T> for [T] { fn lower_bound(&self, x: &T) -> usize { if self[0] >= *x { return 0; } let mut lf = 0; let mut rg = self.len(); // self[lf] < x while rg - lf > 1 { let md = (rg + lf) / 2; if self[md] < *x { lf = md; } else { rg = md; } } rg } // min index self[i] > x // that is, any j (j < i) holds self[j] <= x fn upper_bound(&self, x: &T) -> usize { if self[0] > *x { return 0; } let mut lf = 0; let mut rg = self.len(); // self[lf] <= x while rg - lf > 1 { let md = (rg + lf) / 2; if self[md] <= *x { lf = md; } else { rg = md; } } rg } fn split_by(&self, x: &T) -> (Range<usize>, Range<usize>, Range<usize>) { let i = self.lower_bound(x); let j = self.upper_bound(x); (0..i, i..j, j..self.len()) } } } pub struct UnionFind { par: Vec<usize>, size: Vec<usize>, } impl UnionFind { pub fn new(n: usize) -> UnionFind { UnionFind { par: (0..n).map(|i| i).collect::<Vec<_>>(), size: vec![1; n], } } pub fn find(&mut self, i: usize) -> usize { if self.par[i] == i { self.par[i] } else { self.par[i] = self.find(self.par[i]); self.par[i] } } pub fn unite(&mut self, i: usize, j: usize) { let i = self.find(i); let j = self.find(j); if i == j { return; } let (i, j) = if self.size[i] >= self.size[j] { (i, j) } else { (j, i) }; self.par[j] = i; self.size[i] += self.size[j]; } pub fn get_size(&mut self, i: usize) -> usize { let p = self.find(i); self.size[p] } } use binary_search::BinarySearch; fn main() { let n: usize = read(); let a: i64 = read(); let b: i64 = read(); let x: Vec<i64> = (0..n).map(|_| read()).collect::<Vec<_>>(); let mut uf = UnionFind::new(n); let mut c = vec![0; n + 1]; for (i, &y) in x.iter().enumerate() { let j = x.lower_bound(&(y + a)); let k = x.upper_bound(&(y + b)); if j < k { uf.unite(i, j); c[j] += 1; c[k - 1] -= 1; } } for i in 0..n { c[i + 1] += c[i]; } for i in 0..(n - 1) { if c[i] > 0 { uf.unite(i, i + 1); } } for i in 0..n { println!("{}", uf.get_size(i)); } }