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 ::>() ;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 ::>() } ;($it :ident ;[u8 ] ) =>{Vec ::from (_read !($it ;String ) .into_bytes () ) } ;($it :ident ;usize1 ) =>{$it .next () .unwrap_or_else (||panic !("input mismatch" ) ) .parse ::() .unwrap_or_else (|e |panic !("{}" ,e ) ) -1 } ;($it :ident ;[usize1 ] ) =>{$it .map (|s |s .parse ::() .unwrap_or_else (|e |panic !("{}" ,e ) ) -1 ) .collect ::>() } ;($it :ident ;[$t :ty ] ) =>{$it .map (|s |s .parse ::<$t >() .unwrap_or_else (|e |panic !("{}" ,e ) ) ) .collect ::>() } ;($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 ) ) ,*) } ;} struct SegmentTree { width: usize, node: Vec, } #[allow(dead_code)] impl SegmentTree { fn new(n: usize) -> Self { let width = n.next_power_of_two(); Self { width, node: vec![T::id(); width << 1], } } fn from_vec(a: &[T]) -> Self { let width = a.len().next_power_of_two(); let mut node = vec![T::id(); width << 1]; for i in 0..a.len() { node[i + width] = a[i]; } for i in (1..width).rev() { node[i] = T::f(node[i << 1], node[1 + (i << 1)]); } Self { width, node } } fn update(&mut self, idx: usize, v: T) { let mut now = idx + self.width; self.node[now] = v; now = now >> 1; while now > 0 { self.node[now] = T::f(self.node[now << 1], self.node[1 + (now << 1)]); now = now >> 1; } } fn get(&self, idx: usize) -> T { self.node[idx + self.width] } fn __prod(&self, idx: usize, lc: usize, rc: usize, l: usize, r: usize) -> T { if rc <= l || r <= lc { T::id() } else if l <= lc && rc <= r { self.node[idx] } else { T::f( self.__prod(idx << 1, lc, (lc + rc) / 2, l, r), self.__prod(1 + (idx << 1), (lc + rc) / 2, rc, l, r), ) } } fn prod(&self, range: R) -> T where R: std::ops::RangeBounds, { 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(1, 0, self.width, l, r) } } trait Monoid { fn id() -> Self; fn f(a: Self, b: Self) -> Self; } type M = (f64, f64, f64, f64, f64); impl Monoid for M { fn id() -> Self { (0.0, 0.0, 0.0, 0.0, 0.0) } fn f(a: Self, b: Self) -> Self { let mut p = a; let (d, tl, x, y, tr) = b; let rad = (a.4 + tl).to_radians(); p.4 += tl + tr; p.2 += d * rad.cos() + x * rad.cos() - y * rad.sin(); p.3 += d * rad.sin() + x * rad.sin() + y * rad.cos(); p } } fn main() { let (n, q) = read!(usize, usize); let mut seg = SegmentTree::::from_vec(&vec![(1.0, 0.0, 0.0, 0.0, 0.0); n]); for _ in 0..q { let q = read!([usize]); if q[0] == 0 { let i = q[1]; let x = q[2] as f64; let mut p = seg.get(i - 1); p.1 = x; seg.update(i - 1, p); } else if q[0] == 1 { let i = q[1]; let x = q[2] as f64; let mut p = seg.get(i - 1); p.0 = x; seg.update(i - 1, p); } else { let i: usize = q[1]; let (_, _, x, y, _) = M::f(M::id(), seg.prod(..i)); println!("{0:.6} {1:.6}", x, y); } } }