結果
問題 | No.649 ここでちょっとQK! |
ユーザー | hatoo |
提出日時 | 2018-02-09 23:24:15 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,471 bytes |
コンパイル時間 | 14,588 ms |
コンパイル使用メモリ | 380,512 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-10-09 02:24:27 |
合計ジャッジ時間 | 17,689 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 26 ms
5,248 KB |
testcase_04 | WA | - |
testcase_05 | AC | 65 ms
7,552 KB |
testcase_06 | AC | 40 ms
5,248 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 1 ms
5,248 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 39 ms
5,248 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 1 ms
5,248 KB |
testcase_28 | AC | 1 ms
5,248 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
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 => p = (x, buf.get(&x).cloned().unwrap()), 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(); } } } }); }