Skip to content

Commit

Permalink
abc330 e
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Dec 20, 2023
1 parent 275ec85 commit 0684e38
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions cargo-atcoder-1.70.0/contests/abc330/src/bin/e.rs
@@ -1,10 +1,35 @@
use std::collections::{BTreeSet, HashMap};

use proconio::{input, marker::Usize1};

fn main() {
input! {
n: usize,
a: [Usize1; n],
q: usize,
mut a: [usize; n],
ix: [(Usize1, usize); q]
};
let ans = n - a.len();
println!("{}", ans);

let mut used = HashMap::new();
let mut unused = (0..=2 * 100_000).collect::<BTreeSet<usize>>();
for a_i in a.iter().copied() {
*used.entry(a_i).or_insert(0) += 1;
unused.remove(&a_i);
}

for (i, x) in ix {
let count = used.get_mut(&a[i]).unwrap();
*count -= 1;
if *count == 0 {
used.remove(&a[i]);
unused.insert(a[i]);
}

a[i] = x;
*used.entry(x).or_insert(0) += 1;
unused.remove(&x);

let mex = unused.iter().next().unwrap();
println!("{}", mex);
}
}

0 comments on commit 0684e38

Please sign in to comment.