結果
問題 | No.678 2Dシューティングゲームの必殺ビーム |
ユーザー | hatoo |
提出日時 | 2018-05-03 18:20:28 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 9,052 bytes |
コンパイル時間 | 13,302 ms |
コンパイル使用メモリ | 377,560 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 00:47:35 |
合計ジャッジ時間 | 14,490 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 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::io::{stdin, stdout, BufWriter, Write}; #[allow(unused_imports)] use std::iter::FromIterator; mod util { use std::fmt::Debug; use std::io::{stdin, stdout, BufWriter, StdoutLock}; use std::str::FromStr; #[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 chars() -> Vec<char> { line().chars().collect() } #[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 < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } const BIG_STACK_SIZE: bool = true; #[allow(dead_code)] fn main() { use std::thread; if BIG_STACK_SIZE { thread::Builder::new() .stack_size(32 * 1024 * 1024) .name("solve".into()) .spawn(solve) .unwrap() .join() .unwrap(); } else { solve(); } } #[allow(dead_code)] /// Lazy Segment Tree pub struct SEG<T: SEGimpl> { n: usize, buf: Vec<T::Elem>, zero: T::Elem, phantom: std::marker::PhantomData<T>, } impl<T: SEGimpl> SEG<T> { #[allow(dead_code)] pub fn new(n: usize, zero: T::Elem) -> SEG<T> { let n = (1..).map(|i| 1 << i).find(|&x| x >= n).unwrap(); SEG { n: n, buf: vec![zero.clone(); 2 * n], zero: zero, phantom: std::marker::PhantomData, } } #[allow(dead_code)] fn eval(&mut self, k: usize, l: usize, r: usize) { if r - l > 1 { let (l, r) = self.buf.split_at_mut(2 * k + 1); let (c1, c2) = r.split_at_mut(1); T::eval(&mut l[k], Some((&mut c1[0], &mut c2[0]))); } else { T::eval(&mut self.buf[k], None); } } #[allow(dead_code)] pub fn update(&mut self, i: usize, x: T::Elem) { let mut k = i + self.n - 1; self.buf[k] = x; self.eval(k, i, i + 1); while k > 0 { k = (k - 1) / 2; let (l, r) = self.buf.split_at_mut(2 * k + 1); let (c1, c2) = r.split_at_mut(1); T::reduce(&mut l[k], &c1[0], &c2[0]); } } #[allow(dead_code)] pub fn get(&mut self, i: usize) -> Option<T::R> { self.query(i, i + 1) } #[allow(dead_code)] fn r(&mut self, x: &T::A, a: usize, b: usize, k: usize, l: usize, r: usize) { self.eval(k, l, r); if r <= a || b <= l { return; } if a <= l && r <= b { T::range(x, &mut self.buf[k], l, r); self.eval(k, l, r); return; } self.r(x, a, b, 2 * k + 1, l, (l + r) / 2); self.r(x, a, b, 2 * k + 2, (l + r) / 2, r); let (l, r) = self.buf.split_at_mut(2 * k + 1); let (c1, c2) = r.split_at_mut(1); T::reduce(&mut l[k], &c1[0], &c2[0]); } #[allow(dead_code)] pub fn range_add(&mut self, x: &T::A, a: usize, b: usize) { let n = self.n; self.r(x, a, b, 0, 0, n); } #[allow(dead_code)] pub fn add(&mut self, x: &T::A, i: usize) { self.range_add(x, i, i + 1); } #[allow(dead_code)] fn q(&mut self, a: usize, b: usize, k: usize, l: usize, r: usize) -> Option<T::Elem> { self.eval(k, l, r); if r <= a || b <= l { return None; } if a <= l && r <= b { Some(self.buf[k].clone()) } else { let vl = self.q(a, b, k * 2 + 1, l, (l + r) / 2); let vr = self.q(a, b, k * 2 + 2, (l + r) / 2, r); match (vl, vr) { (Some(l), Some(r)) => { let mut res = self.zero.clone(); T::reduce(&mut res, &l, &r); Some(res) } (Some(l), None) => Some(l), (None, Some(r)) => Some(r), _ => None, } } } #[allow(dead_code)] pub fn query(&mut self, a: usize, b: usize) -> Option<T::R> { let n = self.n; self.q(a, b, 0, 0, n).map(T::to_result) } } pub trait SEGimpl { type Elem: Clone; type A; type R; fn eval(parent: &mut Self::Elem, children: Option<(&mut Self::Elem, &mut Self::Elem)>); fn range(x: &Self::A, elem: &mut Self::Elem, l: usize, r: usize); fn reduce(parent: &mut Self::Elem, c1: &Self::Elem, c2: &Self::Elem); fn to_result(elem: Self::Elem) -> Self::R; } struct BEAM; impl SEGimpl for BEAM { type Elem = (bool, Option<bool>); type A = bool; type R = bool; fn eval(parent: &mut Self::Elem, children: Option<(&mut Self::Elem, &mut Self::Elem)>) { if let Some(b) = parent.1 { if let Some((c1, c2)) = children { c1.1 = Some(b); c2.1 = Some(b); } parent.0 = b; parent.1 = None; } } fn range(x: &Self::A, elem: &mut Self::Elem, _l: usize, _r: usize) { elem.1 = Some(*x); } fn reduce(parent: &mut Self::Elem, c1: &Self::Elem, c2: &Self::Elem) { parent.0 = c1.0 || c2.0; } fn to_result(elem: Self::Elem) -> Self::R { elem.0 } } fn solve() { let (n, mut l, mut r) = get!(usize, usize, usize); let mut es = get!(i32, i32, i32, i32; n); l += 500; r += 500; for e in &mut es { e.0 += 500; e.2 += 500; } let mut ans = vec![false; n]; let mut es = es.into_iter().enumerate().collect::<Vec<_>>(); es.sort_by_key(|e| -(e.1).3); let mut seg: SEG<BEAM> = SEG::new(4000, (false, None)); seg.range_add(&true, l, r + 1); for (i, e) in es { let x1 = e.0 as usize; let x2 = e.2 as usize; ans[i] = seg.query(x1, x2 + 1).unwrap(); seg.range_add(&false, x1, x2 + 1); } util::with_bufwriter(|mut out| { for a in ans { writeln!(out, "{}", if a { 1 } else { 0 }).unwrap(); } }); }