結果

問題 No.1226 I hate Robot Arms
ユーザー o2co2c
提出日時 2020-09-12 01:05:48
言語 Rust
(1.77.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 4,410 bytes
コンパイル時間 2,578 ms
コンパイル使用メモリ 147,808 KB
実行使用メモリ 15,976 KB
最終ジャッジ日時 2023-08-30 11:23:30
合計ジャッジ時間 12,689 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 56 ms
4,384 KB
testcase_03 AC 64 ms
5,404 KB
testcase_04 AC 73 ms
13,540 KB
testcase_05 AC 63 ms
15,016 KB
testcase_06 AC 171 ms
14,428 KB
testcase_07 AC 51 ms
4,384 KB
testcase_08 AC 19 ms
13,664 KB
testcase_09 AC 119 ms
5,328 KB
testcase_10 AC 15 ms
4,384 KB
testcase_11 AC 80 ms
13,368 KB
testcase_12 AC 45 ms
7,896 KB
testcase_13 AC 34 ms
14,892 KB
testcase_14 AC 144 ms
5,364 KB
testcase_15 AC 14 ms
14,512 KB
testcase_16 AC 164 ms
14,900 KB
testcase_17 AC 46 ms
5,936 KB
testcase_18 AC 31 ms
6,080 KB
testcase_19 AC 84 ms
15,008 KB
testcase_20 AC 77 ms
13,344 KB
testcase_21 AC 105 ms
13,428 KB
testcase_22 AC 170 ms
15,312 KB
testcase_23 AC 171 ms
15,824 KB
testcase_24 AC 165 ms
15,328 KB
testcase_25 AC 171 ms
15,732 KB
testcase_26 AC 168 ms
15,292 KB
testcase_27 AC 198 ms
15,976 KB
testcase_28 AC 197 ms
15,240 KB
testcase_29 AC 198 ms
15,316 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
   --> 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`
...
104 | ... = 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)

warning: 1 warning emitted

ソースコード

diff #

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 ) ) ,*) } ;}

struct SegmentTree<T> {
    width: usize,
    node: Vec<T>,
}
#[allow(dead_code)]
impl<T: Monoid + Copy + Clone> SegmentTree<T> {
    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<R>(&self, range: R) -> T
    where
        R: std::ops::RangeBounds<usize>,
    {
        let mut l = match range.start_bound() {
            std::ops::Bound::Included(&a) => a,
            _ => 0,
        } + self.width;
        let mut r = match range.end_bound() {
            std::ops::Bound::Excluded(&a) => a,
            std::ops::Bound::Included(&a) => a + 1,
            _ => self.width,
        } + self.width;
        let mut x = T::id();
        let mut y = T::id();
        while l < r {
            if l % 2 == 1 {
                x = T::f(x, self.node[l]);
                l += 1;
            }
            if r % 2 == 1 {
                r -= 1;
                y = T::f(self.node[r], y);
            }
            l >>= 1;
            r >>= 1;
        }
        T::f(x, y)
    }
}

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::<M>::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, _) = seg.prod(..i);
            println!("{0:.6} {1:.6}", x, y);
        } }
}
0