結果

問題 No.510 二次漸化式
ユーザー packet0packet0
提出日時 2017-04-30 03:02:47
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2,079 ms / 3,000 ms
コード長 1,830 bytes
コンパイル時間 12,651 ms
コンパイル使用メモリ 392,368 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-13 19:22:27
合計ジャッジ時間 37,056 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `q`
  --> src/main.rs:26:9
   |
26 |     let q: usize = lines.next().unwrap().unwrap().parse().unwrap();
   |         ^ help: if this is intentional, prefix it with an underscore: `_q`
   |
   = note: `#[warn(unused_variables)]` on by default

ソースコード

diff #

use std::io::{self, BufRead};

const DIV: usize = 1000000007;

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();

    let n0: usize = lines.next().unwrap().unwrap().parse().unwrap();
    let n1 = n0 + 1;
    let mut x = vec![0; n1];
    let mut y = vec![0; n1];
    let mut a = vec![0; n1];
    let mut b = vec![0; n1];
    let mut b2 = vec![0; n1];
    a[0] = 1;
    b[0] = 1;
    b2[0] = 1;
    let mut ai = 0;
    let mut bi = 0;
    // println!("x{:?}", x);
    // println!("y{:?}", y);
    // println!("a{:?}", a);
    // println!("b{:?}", b);

    let q: usize = lines.next().unwrap().unwrap().parse().unwrap();

    for line in lines {
        let line2 = line.unwrap();
        let list: Vec<&str> = line2.split_whitespace().collect();
        let v = list[1].parse::<usize>().unwrap();
        match list[0].as_bytes()[0] as char {
            'x' => {
                x[v] = list[2].parse().unwrap();
                if v < ai {ai = v};
            },
            'y' => {
                y[v] = list[2].parse().unwrap();
                if v < ai {ai = v};
                if v < bi {bi = v};
            },
            'a' => {
                while bi < v {
                    let next = bi + 1;
                    b[next] = (b[bi] * y[bi] + 1) % DIV;
                    b2[next] = b[next] * b[next] % DIV;
                    bi = next;
                }
                while ai < v {
                    let next = ai + 1;
                    a[next] = ((b2[ai] * x[ai]) % DIV + a[ai]) % DIV;
                    ai = next;
                }
                println!("{}", a[v] % DIV);
            },
            _ => panic!(),
        }
        // println!("x{:?}", x);
        // println!("y{:?}", y);
        // println!("a{:?}", a);
        // println!("b{:?}", b);
    }
}
0