結果

問題 No.1705 Mode of long array
ユーザー phsplsphspls
提出日時 2022-10-02 11:14:11
言語 Rust
(1.77.0)
結果
AC  
実行時間 194 ms / 3,000 ms
コード長 1,864 bytes
コンパイル時間 2,138 ms
コンパイル使用メモリ 159,512 KB
実行使用メモリ 23,328 KB
最終ジャッジ日時 2023-08-26 06:20:10
合計ジャッジ時間 13,501 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 7 ms
4,376 KB
testcase_07 AC 9 ms
4,380 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 157 ms
18,996 KB
testcase_14 AC 103 ms
12,264 KB
testcase_15 AC 94 ms
5,528 KB
testcase_16 AC 120 ms
7,164 KB
testcase_17 AC 81 ms
5,536 KB
testcase_18 AC 67 ms
5,588 KB
testcase_19 AC 132 ms
10,020 KB
testcase_20 AC 81 ms
7,708 KB
testcase_21 AC 125 ms
16,488 KB
testcase_22 AC 194 ms
21,532 KB
testcase_23 AC 41 ms
4,376 KB
testcase_24 AC 42 ms
4,380 KB
testcase_25 AC 41 ms
4,376 KB
testcase_26 AC 41 ms
4,380 KB
testcase_27 AC 40 ms
4,380 KB
testcase_28 AC 41 ms
4,376 KB
testcase_29 AC 41 ms
4,380 KB
testcase_30 AC 41 ms
4,376 KB
testcase_31 AC 41 ms
4,376 KB
testcase_32 AC 41 ms
4,376 KB
testcase_33 AC 173 ms
23,256 KB
testcase_34 AC 177 ms
23,252 KB
testcase_35 AC 177 ms
23,268 KB
testcase_36 AC 170 ms
23,268 KB
testcase_37 AC 180 ms
23,316 KB
testcase_38 AC 175 ms
23,328 KB
testcase_39 AC 172 ms
23,268 KB
testcase_40 AC 184 ms
23,256 KB
testcase_41 AC 180 ms
23,328 KB
testcase_42 AC 173 ms
23,312 KB
testcase_43 AC 170 ms
9,184 KB
testcase_44 AC 168 ms
9,336 KB
testcase_45 AC 168 ms
9,336 KB
testcase_46 AC 169 ms
9,268 KB
testcase_47 AC 168 ms
9,260 KB
testcase_48 AC 170 ms
9,332 KB
testcase_49 AC 93 ms
9,348 KB
testcase_50 AC 94 ms
9,244 KB
testcase_51 AC 94 ms
9,336 KB
testcase_52 AC 95 ms
9,332 KB
testcase_53 AC 94 ms
9,344 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
 --> Main.rs:8:9
  |
8 |     let n = nm[0];
  |         ^ help: if this is intentional, prefix it with an underscore: `_n`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::collections::{BTreeMap, BTreeSet};


fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).ok();
    let a: Vec<usize> = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut q = String::new();
    std::io::stdin().read_line(&mut q).ok();
    let q: usize = q.trim().parse().unwrap();
    let queries = (0..q).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
            (temp[0], temp[1], temp[2])
        })
        .collect::<Vec<_>>();

    let mut mapping = BTreeMap::new();
    let mut revmap = vec![0usize; m+1];
    for i in 0..m {
        mapping.entry(a[i]).or_insert(BTreeSet::new()).insert(i+1);
        revmap[i+1] = a[i];
    }
    for &(t, x, y) in queries.iter() {
        if t == 1 {
            mapping.get_mut(&revmap[x]).unwrap().remove(&x);
            if mapping.get(&revmap[x]).unwrap().is_empty() {
                mapping.remove(&revmap[x]);
            }
            mapping.entry(revmap[x]+y).or_insert(BTreeSet::new()).insert(x);
            revmap[x] += y;
        } else if t == 2 {
            mapping.get_mut(&revmap[x]).unwrap().remove(&x);
            if mapping.get(&revmap[x]).unwrap().is_empty() {
                mapping.remove(&revmap[x]);
            }
            mapping.entry(revmap[x]-y).or_insert(BTreeSet::new()).insert(x);
            revmap[x] -= y;
        } else {
            println!("{}", mapping.iter().rev().nth(0).unwrap().1.iter().rev().nth(0).unwrap());
        }
    }
}
0