結果
問題 | No.1226 I hate Robot Arms |
ユーザー | o2c |
提出日時 | 2020-09-12 19:08:52 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,178 bytes |
コンパイル時間 | 12,434 ms |
コンパイル使用メモリ | 383,932 KB |
実行使用メモリ | 14,244 KB |
最終ジャッジ日時 | 2024-06-10 18:10:15 |
合計ジャッジ時間 | 20,375 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
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 | - |
コンパイルメッセージ
warning: variable does not need to be mutable --> src/main.rs:8:338 | 8 | ...read {($($t :tt ) ,*;$n :expr ) =>{{let stdin =::std ::io ::stdin () ;let ret =::std ::io ::BufRead ::lines (stdin .lock () ) .take ($n ) .map (|line |{let line =line .unwrap () ;let mut it =line .split_whitespace () ;_read !(it ;$($t ) ,*) } ) .collect ::<Vec <_ >>() ;ret } } ;($($t :tt ) ,*) =>{{let line =readln () ;let mut it =l... | ----^^ | | | help: remove this `mut` ... 153 | ... = read!([usize]); | -------------- in this macro invocation | = note: `#[warn(unused_mut)]` on by default = note: this warning originates in the macro `read` (in Nightly builds, run with -Z macro-backtrace for more info)
ソースコード
pub fn readln() -> String { let mut line = String::new(); ::std::io::stdin() .read_line(&mut line) .unwrap_or_else(|e| panic!("{}", e)); line } macro_rules !read {($($t :tt ) ,*;$n :expr ) =>{{let stdin =::std ::io ::stdin () ;let ret =::std ::io ::BufRead ::lines (stdin .lock () ) .take ($n ) .map (|line |{let line =line .unwrap () ;let mut it =line .split_whitespace () ;_read !(it ;$($t ) ,*) } ) .collect ::<Vec <_ >>() ;ret } } ;($($t :tt ) ,*) =>{{let line =readln () ;let mut it =line .split_whitespace () ;_read !(it ;$($t ) ,*) } } ;} macro_rules !_read {($it :ident ;[char ] ) =>{_read !($it ;String ) .chars () .collect ::<Vec <_ >>() } ;($it :ident ;[u8 ] ) =>{Vec ::from (_read !($it ;String ) .into_bytes () ) } ;($it :ident ;usize1 ) =>{$it .next () .unwrap_or_else (||panic !("input mismatch" ) ) .parse ::<usize >() .unwrap_or_else (|e |panic !("{}" ,e ) ) -1 } ;($it :ident ;[usize1 ] ) =>{$it .map (|s |s .parse ::<usize >() .unwrap_or_else (|e |panic !("{}" ,e ) ) -1 ) .collect ::<Vec <_ >>() } ;($it :ident ;[$t :ty ] ) =>{$it .map (|s |s .parse ::<$t >() .unwrap_or_else (|e |panic !("{}" ,e ) ) ) .collect ::<Vec <_ >>() } ;($it :ident ;$t :ty ) =>{$it .next () .unwrap_or_else (||panic !("input mismatch" ) ) .parse ::<$t >() .unwrap_or_else (|e |panic !("{}" ,e ) ) } ;($it :ident ;$($t :tt ) ,+) =>{($(_read !($it ;$t ) ) ,*) } ;} trait ME { type M: Clone; type E: Clone + PartialEq; fn id_m() -> Self::M; fn id_e() -> Self::E; fn id() -> (Self::M, Self::E) { (Self::id_m(), Self::id_e()) } fn f(a: &Self::M, b: &Self::M) -> Self::M; fn g(a: &Self::M, b: &Self::E) -> Self::M; fn h(a: &Self::E, b: &Self::E) -> Self::E; fn p(a: &Self::E, k: usize) -> Self::E; } struct LazySegmentTree<T: ME> { width: usize, dat: Vec<(T::M, T::E)>, } #[allow(dead_code)] impl<T: ME> LazySegmentTree<T> { fn new(n: usize) -> Self { let width = n.next_power_of_two(); Self { width, dat: vec![T::id(); (width << 1) - 1], } } fn from_vec(a: &[T::M]) -> Self { let width = a.len().next_power_of_two(); let mut dat = vec![T::id(); (width << 1) - 1]; for i in 0..a.len() { dat[i + width - 1].0 = a[i].clone(); } for i in (0..width - 1).rev() { dat[i].0 = T::f(&dat[(i << 1) + 1].0, &dat[(i << 1) + 2].0); } Self { width, dat } } fn __eval(&mut self, now: usize, k: usize) { let e = T::p(&self.dat[now].1, k); self.dat[now].0 = T::g(&self.dat[now].0, &e); if k > 1 { self.dat[(now << 1) + 1].1 = T::h(&self.dat[(now << 1) + 1].1, &self.dat[now].1); self.dat[(now << 1) + 2].1 = T::h(&self.dat[(now << 1) + 2].1, &self.dat[now].1); } self.dat[now].1 = T::id_e(); } fn __update(&mut self, x: &T::E, now: usize, lc: usize, rc: usize, l: usize, r: usize) { self.__eval(now, rc - lc); if l <= lc && rc <= r { self.dat[now].1 = T::h(&self.dat[now].1, x); self.__eval(now, rc - lc); } else if l < rc && lc < r { self.__update(x, (now << 1) + 1, lc, (lc + rc) / 2, l, r); self.__update(x, (now << 1) + 2, (lc + rc) / 2, rc, l, r); self.dat[now].0 = T::f(&self.dat[(now << 1) + 1].0, &self.dat[(now << 1) + 2].0); } } fn update<R>(&mut self, range: R, x: &T::E) where R: std::ops::RangeBounds<usize>, { let l = match range.start_bound() { std::ops::Bound::Included(&a) => a, _ => 0, }; let r = match range.end_bound() { std::ops::Bound::Excluded(&a) => a, std::ops::Bound::Included(&a) => a + 1, _ => self.width, }; self.__update(x, 0, 0, self.width, l, r); } fn __prod(&mut self, now: usize, lc: usize, rc: usize, l: usize, r: usize) -> T::M { self.__eval(now, rc - lc); if rc <= l || r <= lc { T::id_m() } else if l <= lc && rc <= r { self.dat[now].0.clone() } else { T::f( &self.__prod((now << 1) + 1, lc, (lc + rc) >> 1, l, r), &self.__prod((now << 1) + 2, (lc + rc) >> 1, rc, l, r), ) } } fn prod<R>(&mut self, range: R) -> T::M where R: std::ops::RangeBounds<usize>, { let l = match range.start_bound() { std::ops::Bound::Included(&a) => a, _ => 0, }; let r = match range.end_bound() { std::ops::Bound::Excluded(&a) => a, std::ops::Bound::Included(&a) => a + 1, _ => self.width, }; self.__prod(0, 0, self.width, l, r) } } struct Node; impl ME for Node { type M = (f64, f64); type E = (Option<f64>, f64); fn id_m() -> Self::M { (0.0, 0.0) } fn id_e() -> Self::E { (None, 0.0) } fn f((x1, y1): &Self::M, (x2, y2): &Self::M) -> Self::M { (x1 + x2, y1 + y2) } fn g(a: &Self::M, (d, t): &Self::E) -> Self::M { let mut x = a.0; let mut y = a.1; if let Some(d) = d { let r = (x * x + y * y).sqrt(); x *= d / r; y *= d / r; } let t = t.to_radians(); (x * t.cos() - y * t.sin(), x * t.sin() + y * t.cos()) } fn h(a: &Self::E, b: &Self::E) -> Self::E { let d = if b.0 == None { a.0 } else { b.0 }; (d, a.1 + b.1) } fn p(a: &Self::E, _k: usize) -> Self::E { *a } } fn main() { let (n, q) = read!(usize, usize); let mut seg = LazySegmentTree::<Node>::from_vec(&vec![(1.0, 0.0); n]); let mut t = vec![0; n]; for _ in 0..q { let p = read!([usize]); if p[0] == 0 { seg.update(p[1] - 1.., &(None, (p[2] - t[p[1] - 1]) as f64)); t[p[1] - 1] = p[2]; } else if p[0] == 1 { seg.update(p[1] - 1..p[1], &(Some(p[2] as f64), 0.0)); } else { let (x, y) = seg.prod(..p[1]); println!("{0:.8} {1:.8}", x, y); } } }