結果
問題 | No.2710 How many more? |
ユーザー |
|
提出日時 | 2024-08-04 21:55:49 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 196 ms / 2,000 ms |
コード長 | 614 bytes |
コンパイル時間 | 16,778 ms |
コンパイル使用メモリ | 405,912 KB |
実行使用メモリ | 7,180 KB |
最終ジャッジ日時 | 2024-08-04 21:56:53 |
合計ジャッジ時間 | 21,010 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 |
ソースコード
use std::collections::BTreeMap; fn g() -> Vec<usize> { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.split_whitespace().flat_map(str::parse).collect() } fn main() { let q = g()[1]; let a = g(); let mut h = BTreeMap::new(); a.iter().for_each(|&x| *h.entry(x).or_insert(0) += 1); let (mut i, mut d) = (vec![0], vec![0]); for (k, v) in h { d.push(d.last().unwrap() + v); i.push(k); } for _ in 0..q { let z = g(); let x = i.binary_search(&a[z[0] - 1]).map_or(0, |p| d[p - 1]); let y = i.binary_search(&a[z[1] - 1]).map_or(0, |p| d[p]); println!("{}", 0.max(x - y)) } }