結果
| 問題 | No.2710 How many more? |
| コンテスト | |
| ユーザー |
well-defined
|
| 提出日時 | 2024-09-15 18:35:34 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,456 bytes |
| 記録 | |
| コンパイル時間 | 22,474 ms |
| コンパイル使用メモリ | 388,736 KB |
| 実行使用メモリ | 10,344 KB |
| 最終ジャッジ日時 | 2024-09-15 18:36:02 |
| 合計ジャッジ時間 | 27,771 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 11 |
ソースコード
use std::collections::HashMap;
use std::hash::Hash;
use proconio::input;
fn value_and_count<T: Hash + Eq + Clone>(arr: &[T]) -> HashMap<T, usize> {
let mut ans = Vec::new();
let mut count = 0;
let mut current: Option<&T> = None;
for val in arr {
match current {
Some(cur) if cur == val => {
},
_ => {
if let Some(cur) = current {
ans.push((cur.clone(), count));
}
current = Some(val);
},
}
count += 1;
}
if let Some(cur) = current {
ans.push((cur.clone(), count));
}
ans.into_iter().collect::<HashMap<_,_>>()
}
fn main () {
input! {
n: usize,
q: usize,
a: [usize; n],
}
let mut acopy = a.clone();
acopy.sort();
let range_people = value_and_count(&acopy);
let num_range = a.iter()
.enumerate()
.map(|(i, &x)| {
(i+1, x)
})
.collect::<HashMap<_,_>>();
//println!("{:?}",num_range);
//println!("{:?}",range_people);
for _ in 0..q {
input! {
x: usize,
y: usize,
}
let x = *num_range.get(&x).unwrap();
let x = *range_people.get(&x).unwrap() as i64;
let y = *num_range.get(&y).unwrap();
let y = *range_people.get(&y).unwrap() as i64;
println!("{}", if x-y-1 < 0 { 0 } else {x-y-1});
}
}
well-defined