結果

問題 No.510 二次漸化式
ユーザー packet0packet0
提出日時 2017-04-30 03:02:47
言語 Rust
(1.77.0)
結果
AC  
実行時間 2,077 ms / 3,000 ms
コード長 1,830 bytes
コンパイル時間 639 ms
コンパイル使用メモリ 154,056 KB
実行使用メモリ 5,936 KB
最終ジャッジ日時 2023-10-11 20:30:50
合計ジャッジ時間 25,336 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 37 ms
4,352 KB
testcase_03 AC 37 ms
4,352 KB
testcase_04 AC 33 ms
4,348 KB
testcase_05 AC 34 ms
4,352 KB
testcase_06 AC 180 ms
4,348 KB
testcase_07 AC 177 ms
4,352 KB
testcase_08 AC 213 ms
4,352 KB
testcase_09 AC 214 ms
4,348 KB
testcase_10 AC 17 ms
4,348 KB
testcase_11 AC 17 ms
4,352 KB
testcase_12 AC 18 ms
4,348 KB
testcase_13 AC 17 ms
4,348 KB
testcase_14 AC 18 ms
4,352 KB
testcase_15 AC 17 ms
4,348 KB
testcase_16 AC 1,043 ms
5,688 KB
testcase_17 AC 822 ms
5,928 KB
testcase_18 AC 844 ms
5,680 KB
testcase_19 AC 829 ms
5,936 KB
testcase_20 AC 1,001 ms
5,704 KB
testcase_21 AC 1,007 ms
5,920 KB
testcase_22 AC 1,029 ms
5,616 KB
testcase_23 AC 2,066 ms
5,652 KB
testcase_24 AC 2,077 ms
5,652 KB
testcase_25 AC 2,028 ms
5,696 KB
testcase_26 AC 2,016 ms
5,928 KB
testcase_27 AC 1,978 ms
5,932 KB
testcase_28 AC 1,645 ms
5,696 KB
testcase_29 AC 1,659 ms
5,680 KB
testcase_30 AC 1,635 ms
5,612 KB
testcase_31 AC 8 ms
5,076 KB
testcase_32 AC 8 ms
5,136 KB
testcase_33 AC 9 ms
5,848 KB
testcase_34 AC 34 ms
4,352 KB
testcase_35 AC 32 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `q`
  --> 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

warning: 1 warning emitted

ソースコード

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