結果
| 問題 |
No.2220 Range Insert & Point Mex
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-17 22:31:58 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 328 ms / 2,000 ms |
| コード長 | 1,951 bytes |
| コンパイル時間 | 17,062 ms |
| コンパイル使用メモリ | 380,080 KB |
| 実行使用メモリ | 34,464 KB |
| 最終ジャッジ日時 | 2024-07-21 12:47:06 |
| 合計ジャッジ時間 | 22,319 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#![allow(dead_code, unused_imports, unused_macros, non_snake_case)]
fn main() {
let mut input = VecDeque::from(read_all_words());
let N = input.pop_front().unwrap().parse::<usize>().unwrap();
let mut queries = vec![];
for _ in 0 .. N {
let l = input.pop_front().unwrap().parse::<usize>().unwrap();
let r = input.pop_front().unwrap().parse::<usize>().unwrap() + 1;
let a = input.pop_front().unwrap().parse::<i64>().unwrap();
queries.push((l, 1, a));
queries.push((r, -1, a));
}
queries.sort();
let mut queries = VecDeque::from(queries);
let Q = input.pop_front().unwrap().parse::<usize>().unwrap();
let x = (0 .. Q).map(|_| input.pop_front().unwrap().parse::<usize>().unwrap() ).collect::<Vec<_>>();
let mut mex = (0 .. 200000).collect::<BTreeSet<_>>();
let mut count = BTreeMap::new();
for i in x {
while let Some(&(j, s, a)) = queries.front() {
if j > i {
break;
}
queries.pop_front();
if s == 1 {
*count.entry(a).or_insert(0) += 1;
if count[&a] == 1 {
mex.remove(&a);
}
} else {
*count.get_mut(&a).unwrap() -= 1;
if count[&a] == 0 {
mex.insert(a);
}
}
}
println!("{}", *mex.range(0 ..).next().unwrap());
}
}
type Int = i64;
use std::collections::*;
const MOD: Int = 1_000_000_007;
const INF: Int = 1_000_000_000;
const YESNO: [&'static str; 2] = ["Yes", "No"];
use std::io::*;
fn read_all_words() -> Vec<String> { let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).ok(); buf.split_whitespace().map(str::to_owned).collect() }
fn yes() { println!("{}", YESNO[0]); }
fn no() { println!("{}", YESNO[1]); }
fn yesno(c: bool) { println!("{}", if c { YESNO[0] } else { YESNO[1] }); }