結果

問題 No.2710 How many more?
ユーザー well-definedwell-defined
提出日時 2024-09-15 18:35:34
言語 Rust
(1.77.0)
結果
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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 302 ms
9,088 KB
testcase_03 AC 224 ms
8,660 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 74 ms
6,940 KB
testcase_08 AC 52 ms
6,940 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 135 ms
6,940 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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});
    }
    
}
0