結果
問題 | No.1675 Strange Minimum Query |
ユーザー | ziita |
提出日時 | 2021-09-10 21:49:11 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,366 bytes |
コンパイル時間 | 12,853 ms |
コンパイル使用メモリ | 403,512 KB |
実行使用メモリ | 31,376 KB |
最終ジャッジ日時 | 2024-06-11 23:27:18 |
合計ジャッジ時間 | 27,958 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | AC | 256 ms
13,780 KB |
testcase_04 | AC | 300 ms
18,176 KB |
testcase_05 | AC | 89 ms
10,752 KB |
testcase_06 | AC | 307 ms
15,232 KB |
testcase_07 | AC | 376 ms
21,632 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
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 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
ソースコード
#![allow(unused_imports)] #![allow(non_snake_case, unused)] // ---------- begin input macro ---------- // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- use std::cmp::*; use std::collections::*; use std::ops::*; use std::marker::*; const INF: i64 = std::i64::MAX/100; const MOD: i64 = 1_000_000_007; // const MOD: i64 = 998_244_353; // ---------- begin lazy segment tree ---------- // https://yukicoder.me/submissions/379658 より pub trait TE { type T: Clone; type E: Clone; fn fold(l:Self::T, r:Self::T) -> Self::T; fn eval(p:Self::T, x:Self::E) -> Self::T; fn merge(f:Self::E, g:Self::E) -> Self::E; fn e() -> Self::T; fn id() -> Self::E; } pub struct LazySegmentTree<R: TE> { size: usize, bit: usize, a: Vec<(R::T, R::E)>, } impl <R: TE> LazySegmentTree<R> { pub fn new(n: usize) -> LazySegmentTree<R> { let mut bit = 0; while (1 << bit) < n { bit += 1; } LazySegmentTree { size: 1 << bit, bit: bit, a: vec![(R::e(), R::id()); 2 << bit], } } pub fn build_by(z: &[R::T]) -> LazySegmentTree<R> { let n = z.len(); let mut bit = 0; while (1 << bit) < n { bit += 1; } let mut a = vec![(R::e(), R::id()); 2 << bit]; for (a, z) in a[(1 << bit)..].iter_mut().zip(z.iter()) { a.0 = z.clone(); } for i in (1..(1 << bit)).rev() { let l = R::eval(a[2 * i].0.clone(), a[2 * i].1.clone()); let r = R::eval(a[2 * i + 1].0.clone(), a[2 * i + 1].1.clone()); a[i].0 = R::fold(l, r); } LazySegmentTree { size: 1 << bit, bit : bit, a: a, } } fn eval(&self, k: usize) -> R::T { R::eval(self.a[k].0.clone(), self.a[k].1.clone()) } fn propagate(&mut self, x: usize) { let x = x + self.size; for i in (1..(self.bit + 1)).rev() { let k = x >> i; self.a[2 * k].1 = R::merge(self.a[2 * k].1.clone(), self.a[k].1.clone()); self.a[2 * k + 1].1 = R::merge(self.a[2 * k + 1].1.clone(), self.a[k].1.clone()); self.a[k].1 = R::id(); self.a[k].0 = R::fold(self.eval(2 * k), self.eval(2 * k + 1)); } } fn save(&mut self, x: usize) { let x = x + self.size; for i in 1..(self.bit + 1) { let k = x >> i; self.a[k].0 = R::fold(self.eval(2 * k), self.eval(2 * k + 1)); } } pub fn update(&mut self, l: usize, r: usize, op: R::E) { self.propagate(l); self.propagate(r - 1); let mut x = l + self.size; let mut y = r + self.size; while x < y { if x & 1 == 1 { self.a[x].1 = R::merge(self.a[x].1.clone(), op.clone()); x += 1; } if y & 1 == 1 { y -= 1; self.a[y].1 = R::merge(self.a[y].1.clone(), op.clone()); } x >>= 1; y >>= 1; } self.save(l); self.save(r - 1); } pub fn find(&mut self, l: usize, r: usize) -> R::T { self.propagate(l); self.propagate(r - 1); let mut x = l + self.size; let mut y = r + self.size; let mut p = R::e(); let mut q = R::e(); while x < y { if x & 1 == 1 { p = R::fold(p, self.eval(x)); x += 1; } if y & 1 == 1 { y -= 1; q = R::fold(self.eval(y), q); } x >>= 1; y >>= 1; } R::fold(p, q) } } struct R; impl TE for R { type T = (i64,usize); type E = (i64,usize); fn fold(l: Self::T, r: Self::T) -> Self::T { min(l,r) } fn eval(p: Self::T, x: Self::E) -> Self::T { if x.1>p.1 { x } else { p } } fn merge(f: Self::E, g: Self::E) -> Self::E { if f.1>g.1 { f } else { g } } fn e() -> Self::T { (1_000_000_000,0) } fn id() -> Self::E { (1_000_000_000,0) } } // ---------- end lazy segment tree ---------- fn main() { input! { n: usize, q: usize, lrb: [(usize,usize,i64);q], } let mut seg = LazySegmentTree::<R>::new(n); for i in 0..n { seg.update(i,i+1,(1_000_000_000,0)); } let mut v = vec![]; for &(l,r,b) in &lrb { v.push((b,l-1,r-1)); } v.sort(); let mut idx = 1; for &(b,l,r) in &v { seg.update(l,r+1,(b,idx)); idx += 1; } for &(b,l,r) in &v { let v = seg.find(l,r+1); if b!=v.0 { println!("-1"); return; } } for i in 0..n { print!("{} ",seg.find(i,i+1).0); } }