結果
問題 |
No.1705 Mode of long array
|
ユーザー |
|
提出日時 | 2022-10-02 11:14:11 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 193 ms / 3,000 ms |
コード長 | 1,864 bytes |
コンパイル時間 | 23,896 ms |
コンパイル使用メモリ | 399,588 KB |
実行使用メモリ | 23,424 KB |
最終ジャッジ日時 | 2024-12-24 21:31:30 |
合計ジャッジ時間 | 29,581 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
コンパイルメッセージ
warning: unused variable: `n` --> src/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
ソースコード
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()); } } }