結果
問題 |
No.2710 How many more?
|
ユーザー |
|
提出日時 | 2024-03-31 14:12:15 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 169 ms / 2,000 ms |
コード長 | 1,446 bytes |
コンパイル時間 | 11,522 ms |
コンパイル使用メモリ | 391,204 KB |
実行使用メモリ | 10,724 KB |
最終ジャッジ日時 | 2024-09-30 19:09:09 |
合計ジャッジ時間 | 14,765 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 |
ソースコード
use std::collections::HashMap; fn main() { let stdin = std::io::stdin(); let mut line = String::new(); stdin.read_line(&mut line).unwrap(); let line: Vec<&str> = line.split_whitespace().collect(); let _n = line[0].parse::<usize>().unwrap(); let q = line[1].parse::<usize>().unwrap(); let mut line = String::new(); stdin.read_line(&mut line).unwrap(); let a: Vec<i64> = line .split_whitespace() .map(|s| s.parse::<i64>().unwrap()) .collect(); let mut dist: Vec<i64> = a.clone(); dist.sort(); let mut count = HashMap::<i64, usize>::default(); let mut cum_count: HashMap<_, _> = HashMap::default(); for (i, &pos) in dist.iter().enumerate() { *count.entry(pos).or_insert(0) += 1; cum_count.insert(pos, i + 1); } for _i in 0..q { let mut line = String::new(); stdin.read_line(&mut line).unwrap(); let q: Vec<usize> = line .split_whitespace() .map(|s| s.parse::<usize>().unwrap()) .collect(); let (x, y) = (q[0], q[1]); let pos_x = a[x - 1]; let pos_y = a[y - 1]; if pos_x <= pos_y { println!("0"); } else { println!( "{}", cum_count.get(&pos_x).unwrap() - count.get(&pos_x).unwrap() - cum_count.get(&pos_y).unwrap() ); } } }