結果
問題 | No.649 ここでちょっとQK! |
ユーザー | hatoo |
提出日時 | 2018-02-10 15:04:11 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1,714 ms / 3,000 ms |
コード長 | 5,681 bytes |
コンパイル時間 | 11,928 ms |
コンパイル使用メモリ | 384,648 KB |
実行使用メモリ | 15,104 KB |
最終ジャッジ日時 | 2024-10-13 12:08:19 |
合計ジャッジ時間 | 23,288 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 40 ms
12,772 KB |
testcase_04 | AC | 1,714 ms
15,104 KB |
testcase_05 | AC | 90 ms
15,104 KB |
testcase_06 | AC | 808 ms
15,024 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
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 | AC | 237 ms
8,608 KB |
testcase_13 | AC | 235 ms
8,348 KB |
testcase_14 | AC | 229 ms
8,480 KB |
testcase_15 | AC | 223 ms
8,484 KB |
testcase_16 | AC | 207 ms
8,484 KB |
testcase_17 | AC | 245 ms
9,088 KB |
testcase_18 | AC | 291 ms
9,784 KB |
testcase_19 | AC | 340 ms
10,460 KB |
testcase_20 | AC | 387 ms
11,016 KB |
testcase_21 | AC | 433 ms
11,688 KB |
testcase_22 | AC | 498 ms
12,316 KB |
testcase_23 | AC | 551 ms
12,996 KB |
testcase_24 | AC | 621 ms
13,696 KB |
testcase_25 | AC | 678 ms
14,336 KB |
testcase_26 | AC | 750 ms
14,968 KB |
testcase_27 | AC | 1 ms
5,248 KB |
testcase_28 | AC | 1 ms
5,248 KB |
testcase_29 | AC | 1 ms
5,248 KB |
testcase_30 | AC | 231 ms
8,476 KB |
testcase_31 | AC | 205 ms
8,604 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)] /// Generic Binary Indexed Tree pub struct BIT<T: Clone, F: Fn(&mut T, &T) -> ()> { buf: Vec<T>, zero: T, f: F, } impl<T: Clone, F: Fn(&mut T, &T) -> ()> BIT<T, F> { #[allow(dead_code)] pub fn new(n: usize, zero: &T, f: F) -> BIT<T, F> { BIT { buf: vec![zero.clone(); n + 1], zero: zero.clone(), f: f, } } #[allow(dead_code)] pub fn sum(&self, i: usize) -> T { let mut i = i; let mut s = self.zero.clone(); while i > 0 { (self.f)(&mut s, &self.buf[i]); i &= i - 1; } s } #[allow(dead_code)] pub fn add(&mut self, i: usize, x: &T) { let mut i = i as i64; while i < self.buf.len() as i64 { let t = &mut self.buf[i as usize]; (self.f)(t, x); i += i & -i; } } } #[allow(dead_code)] fn main() { let (q, k) = get!(usize, usize); let inputs = get!(String; q); let mut cc: Vec<u64> = inputs .iter() .filter_map(|s| { let mut split = s.split_whitespace(); if split.next() == Some("1") { split.next().unwrap().parse().ok() } else { None } }) .collect(); cc.sort(); cc.dedup(); let mut buf: Vec<u32> = Vec::with_capacity(q); util::with_bufwriter(|mut out| { for line in inputs { let mut split = line.split_whitespace(); if split.next() == Some("1") { let x: u64 = split.next().unwrap().parse().unwrap(); let y = cc.binary_search(&x).unwrap(); let i = match buf.binary_search(&(y as u32)) { Ok(i) => i, Err(i) => i, }; buf.insert(i, y as u32); } else { if let Some(ans) = buf.get(k - 1).cloned() { writeln!(out, "{}", cc[ans as usize]).unwrap(); buf.remove(k - 1); } else { writeln!(out, "-1").unwrap(); } } } }); }