結果

問題 No.2710 How many more?
ユーザー well-definedwell-defined
提出日時 2024-09-16 15:30:43
言語 Rust
(1.77.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,202 bytes
コンパイル時間 16,060 ms
コンパイル使用メモリ 374,588 KB
実行使用メモリ 9,516 KB
最終ジャッジ日時 2024-09-16 15:31:03
合計ジャッジ時間 18,090 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 161 ms
7,808 KB
testcase_03 AC 89 ms
7,424 KB
testcase_04 AC 62 ms
8,324 KB
testcase_05 AC 48 ms
5,496 KB
testcase_06 AC 52 ms
7,828 KB
testcase_07 AC 71 ms
5,376 KB
testcase_08 AC 49 ms
5,376 KB
testcase_09 AC 131 ms
8,184 KB
testcase_10 AC 74 ms
5,504 KB
testcase_11 AC 125 ms
5,376 KB
testcase_12 AC 174 ms
9,076 KB
testcase_13 AC 192 ms
9,508 KB
testcase_14 AC 189 ms
9,508 KB
testcase_15 AC 192 ms
9,512 KB
testcase_16 AC 192 ms
9,508 KB
testcase_17 AC 186 ms
9,516 KB
testcase_18 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use proconio::input;
use std::collections::HashMap;
fn main () {
    input! {
        n: u64,
        q: u64,
        mut a: [u64; n],
    }
    let acopy = a.clone();
    a.sort_by(|&a, &b| b.cmp(&a));
    a.dedup();
    let d =  a.iter()
        .enumerate()
        .map(|(i, &x)| {
            (x, i as u64)
        })
        .collect::<HashMap<u64, u64>>();
    //println!("{:?}", d);
    let mut count : Vec<u64> = vec![0; d.len()];
    for &v in &acopy {
        let l = *d.get(&v).unwrap();
        count[l as usize] += 1;
    }
    let count: Vec<u64> = count.iter()
        .scan(0, |sum, &x| {
            *sum += x;
            Some(*sum)
        })
        .collect();
    //println!("{:?}", count);
    for _ in 0..q {
        input! {
            x: u64, 
            y: u64,
        }
        let x = acopy[(x-1) as usize];
        let y = acopy[(y-1) as usize];
        //println!("x: {}, y: {}", x, y);
        let x = *d.get(&x).unwrap();
        let y = *d.get(&y).unwrap();
        //println!("x: {}, y: {}", x, y);
        println!("{}", 
            if y == 0 || count[(y-1) as usize] < count[x as usize]{0}
            else {count[(y-1) as usize] - count[x as usize]});
    }
}
0