結果

問題 No.2170 Left Addition Machine
ユーザー trineutrontrineutron
提出日時 2022-12-22 22:38:35
言語 Rust
(1.77.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,740 bytes
コンパイル時間 11,372 ms
コンパイル使用メモリ 379,100 KB
実行使用メモリ 16,640 KB
最終ジャッジ日時 2024-04-29 05:43:29
合計ジャッジ時間 23,323 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 124 ms
15,616 KB
testcase_04 AC 27 ms
5,376 KB
testcase_05 AC 47 ms
8,832 KB
testcase_06 AC 47 ms
11,008 KB
testcase_07 AC 64 ms
12,288 KB
testcase_08 AC 13 ms
6,784 KB
testcase_09 AC 49 ms
7,168 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 34 ms
9,216 KB
testcase_12 AC 83 ms
16,384 KB
testcase_13 AC 82 ms
16,384 KB
testcase_14 AC 80 ms
16,384 KB
testcase_15 AC 80 ms
16,384 KB
testcase_16 AC 79 ms
16,384 KB
testcase_17 AC 83 ms
16,384 KB
testcase_18 AC 83 ms
16,384 KB
testcase_19 AC 85 ms
16,384 KB
testcase_20 AC 102 ms
16,384 KB
testcase_21 AC 44 ms
5,376 KB
testcase_22 AC 43 ms
5,376 KB
testcase_23 AC 41 ms
5,376 KB
testcase_24 AC 41 ms
5,376 KB
testcase_25 AC 42 ms
5,376 KB
testcase_26 AC 40 ms
5,376 KB
testcase_27 AC 39 ms
5,376 KB
testcase_28 AC 42 ms
5,376 KB
testcase_29 AC 43 ms
5,376 KB
testcase_30 AC 81 ms
16,256 KB
testcase_31 AC 82 ms
16,384 KB
testcase_32 AC 81 ms
16,512 KB
testcase_33 AC 78 ms
16,384 KB
testcase_34 AC 77 ms
16,384 KB
testcase_35 AC 77 ms
16,384 KB
testcase_36 AC 78 ms
16,384 KB
testcase_37 AC 78 ms
16,256 KB
testcase_38 AC 77 ms
16,384 KB
testcase_39 AC 39 ms
5,376 KB
testcase_40 AC 40 ms
5,376 KB
testcase_41 AC 39 ms
5,376 KB
testcase_42 AC 42 ms
5,376 KB
testcase_43 AC 45 ms
5,376 KB
testcase_44 AC 45 ms
5,376 KB
testcase_45 AC 43 ms
5,376 KB
testcase_46 AC 38 ms
5,376 KB
testcase_47 AC 41 ms
5,376 KB
testcase_48 AC 76 ms
16,384 KB
testcase_49 AC 73 ms
16,384 KB
testcase_50 AC 74 ms
16,384 KB
testcase_51 AC 71 ms
16,384 KB
testcase_52 AC 71 ms
16,384 KB
testcase_53 AC 73 ms
16,512 KB
testcase_54 AC 76 ms
16,384 KB
testcase_55 AC 75 ms
16,384 KB
testcase_56 AC 78 ms
16,384 KB
testcase_57 AC 75 ms
16,512 KB
testcase_58 AC 75 ms
16,512 KB
testcase_59 AC 73 ms
16,640 KB
testcase_60 AC 76 ms
16,512 KB
testcase_61 AC 73 ms
16,512 KB
testcase_62 AC 74 ms
16,384 KB
testcase_63 AC 74 ms
16,512 KB
testcase_64 AC 73 ms
16,512 KB
testcase_65 AC 82 ms
16,384 KB
testcase_66 AC 14 ms
5,376 KB
testcase_67 AC 64 ms
14,848 KB
testcase_68 AC 72 ms
16,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::{io, io::Write};

const MOD: i64 = 998244353;
const HALF: i64 = (MOD + 1) / 2;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let v: Vec<_> = s.split_whitespace().collect();
    let n: usize = v[0].trim().parse().unwrap();
    let q: usize = v[1].trim().parse().unwrap();
    let mut a: Vec<i64> = vec![0; n];
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let v: Vec<_> = s.split_whitespace().collect();
    for i in 0..n {
        a[i] = v[i].trim().parse().unwrap();
    }
    let mut l: Vec<usize> = vec![0; q];
    let mut r: Vec<usize> = vec![0; q];
    for i in 0..q {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        let v: Vec<_> = s.split_whitespace().collect();
        l[i] = v[0].trim().parse().unwrap();
        r[i] = v[1].trim().parse().unwrap();
    }

    let mut last = vec![0; n];
    for i in 1..n {
        if a[i] > a[i - 1] {
            last[i] = last[i - 1];
        } else {
            last[i] = i;
        }
    }

    let mut a_sum = vec![0; n + 1];
    let mut pow_half = vec![1; n + 1];
    let mut mul: i64 = 1;
    for i in 0..n {
        a_sum[i + 1] = (a_sum[i] + mul * a[i]) % MOD;
        mul += mul;
        if mul >= MOD {
            mul -= MOD;
        }
        pow_half[i + 1] = pow_half[i] * HALF % MOD;
    }

    let out = io::stdout();
    let mut out = io::BufWriter::new(out.lock());
    for i in 0..q {
        l[i] -= 1;
        r[i] -= 1;
        l[i] = l[i].max(last[r[i]]);
        writeln!(
            out,
            "{}",
            ((a_sum[r[i] + 1] - a_sum[l[i] + 1] + MOD) * pow_half[l[i] + 1] + a[l[i]]) % MOD
        )
        .unwrap();
    }
}
0