結果
問題 | No.649 ここでちょっとQK! |
ユーザー | hatoo |
提出日時 | 2018-02-09 23:43:39 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 86 ms / 3,000 ms |
コード長 | 5,558 bytes |
コンパイル時間 | 16,797 ms |
コンパイル使用メモリ | 380,200 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-10-09 03:32:24 |
合計ジャッジ時間 | 21,183 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 0 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 23 ms
5,248 KB |
testcase_04 | AC | 71 ms
7,552 KB |
testcase_05 | AC | 59 ms
7,680 KB |
testcase_06 | AC | 40 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 0 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 1 ms
5,248 KB |
testcase_12 | AC | 36 ms
5,248 KB |
testcase_13 | AC | 36 ms
5,248 KB |
testcase_14 | AC | 35 ms
5,248 KB |
testcase_15 | AC | 41 ms
5,248 KB |
testcase_16 | AC | 38 ms
5,248 KB |
testcase_17 | AC | 44 ms
5,248 KB |
testcase_18 | AC | 50 ms
5,248 KB |
testcase_19 | AC | 54 ms
5,248 KB |
testcase_20 | AC | 59 ms
5,248 KB |
testcase_21 | AC | 66 ms
5,248 KB |
testcase_22 | AC | 67 ms
5,248 KB |
testcase_23 | AC | 71 ms
5,248 KB |
testcase_24 | AC | 75 ms
5,248 KB |
testcase_25 | AC | 82 ms
5,376 KB |
testcase_26 | AC | 86 ms
5,632 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 1 ms
5,248 KB |
testcase_29 | AC | 1 ms
5,248 KB |
testcase_30 | AC | 29 ms
5,248 KB |
testcase_31 | AC | 30 ms
5,248 KB |
testcase_32 | AC | 1 ms
5,248 KB |
testcase_33 | AC | 1 ms
5,248 KB |
testcase_34 | AC | 1 ms
5,248 KB |
testcase_35 | AC | 1 ms
5,248 KB |
ソースコード
/** * _ _ __ _ _ _ _ _ _ _ * | | | | / / | | (_) | (_) | | (_) | | * | |__ __ _| |_ ___ ___ / /__ ___ _ __ ___ _ __ ___| |_ _| |_ ___ _____ ______ _ __ _ _ ___| |_ ______ ___ _ __ _ _ __ _ __ ___| |_ ___ * | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __| * | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) | __/ |_| | |_| |\ V / __/ | | | |_| \__ \ |_ \__ \ | | | | |_) | |_) | __/ |_\__ \ * |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___| |_| \__,_|___/\__| |___/_| |_|_| .__/| .__/ \___|\__|___/ * | | | | | | * |_| |_| |_| * * https://github.com/hatoo/competitive-rust-snippets */ #[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::iter::FromIterator; #[allow(unused_imports)] use std::io::{stdin, stdout, BufWriter, Write}; mod util { use std::io::{stdin, stdout, BufWriter, StdoutLock}; use std::str::FromStr; use std::fmt::Debug; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn gets<T: FromStr>() -> Vec<T> where <T as FromStr>::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } #[allow(dead_code)] pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) { let out = stdout(); let writer = BufWriter::new(out.lock()); f(writer) } } #[allow(unused_macros)] macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } #[allow(dead_code)] fn main() { let (q, k) = get!(usize, usize); let mut total = 0; let mut p = (0, 0); let mut buf = BTreeMap::new(); util::with_bufwriter(|mut out| { for _ in 0..q { let input = util::line(); /* debug!(input); debug!(p); debug!(total); debug!(buf); */ let mut split = input.split_whitespace(); if split.next().unwrap().parse::<usize>().unwrap() == 1usize { let x: u64 = split.next().unwrap().parse().unwrap(); total += 1; *buf.entry(x).or_insert(0) += 1; match total.cmp(&k) { Ordering::Equal => { let (&y, &n) = buf.iter().last().unwrap(); p = (y, n); } Ordering::Greater => { if x < p.0 { if p.1 > 1 { p.1 -= 1; } else { let (&y, &n) = buf.range(..p.0).rev().next().unwrap(); p = (y, n); } } } _ => (), } } else { if total >= k { writeln!(out, "{}", p.0).unwrap(); *buf.get_mut(&p.0).unwrap() -= 1; if buf.get(&p.0).unwrap() == &0 { buf.remove(&p.0); } total -= 1; if total >= k { if p.1 <= buf.get(&p.0).cloned().unwrap_or(0) { } else { let (&y, _) = buf.range(p.0 + 1..).next().unwrap(); p = (y, 1); } } } else { writeln!(out, "-1").unwrap(); } } } }); }