結果

問題 No.2170 Left Addition Machine
ユーザー trineutrontrineutron
提出日時 2022-12-22 22:07:51
言語 Rust
(1.77.0)
結果
AC  
実行時間 409 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 13,189 ms
コンパイル使用メモリ 377,504 KB
実行使用メモリ 16,512 KB
最終ジャッジ日時 2024-04-29 05:42:32
合計ジャッジ時間 44,811 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 383 ms
15,616 KB
testcase_04 AC 162 ms
5,376 KB
testcase_05 AC 230 ms
8,832 KB
testcase_06 AC 207 ms
11,008 KB
testcase_07 AC 327 ms
12,288 KB
testcase_08 AC 27 ms
6,656 KB
testcase_09 AC 316 ms
7,168 KB
testcase_10 AC 50 ms
5,376 KB
testcase_11 AC 172 ms
9,216 KB
testcase_12 AC 408 ms
16,384 KB
testcase_13 AC 376 ms
16,384 KB
testcase_14 AC 374 ms
16,384 KB
testcase_15 AC 388 ms
16,384 KB
testcase_16 AC 409 ms
16,384 KB
testcase_17 AC 380 ms
16,384 KB
testcase_18 AC 357 ms
16,256 KB
testcase_19 AC 366 ms
16,384 KB
testcase_20 AC 360 ms
16,512 KB
testcase_21 AC 298 ms
5,376 KB
testcase_22 AC 287 ms
5,376 KB
testcase_23 AC 293 ms
5,376 KB
testcase_24 AC 293 ms
5,376 KB
testcase_25 AC 294 ms
5,376 KB
testcase_26 AC 290 ms
5,376 KB
testcase_27 AC 293 ms
5,376 KB
testcase_28 AC 294 ms
5,376 KB
testcase_29 AC 292 ms
5,376 KB
testcase_30 AC 366 ms
16,384 KB
testcase_31 AC 369 ms
16,384 KB
testcase_32 AC 372 ms
16,384 KB
testcase_33 AC 389 ms
16,256 KB
testcase_34 AC 394 ms
16,384 KB
testcase_35 AC 376 ms
16,512 KB
testcase_36 AC 372 ms
16,384 KB
testcase_37 AC 365 ms
16,384 KB
testcase_38 AC 372 ms
16,384 KB
testcase_39 AC 290 ms
5,376 KB
testcase_40 AC 291 ms
5,376 KB
testcase_41 AC 290 ms
5,376 KB
testcase_42 AC 289 ms
5,376 KB
testcase_43 AC 290 ms
5,376 KB
testcase_44 AC 295 ms
5,376 KB
testcase_45 AC 287 ms
5,376 KB
testcase_46 AC 288 ms
5,376 KB
testcase_47 AC 289 ms
5,376 KB
testcase_48 AC 363 ms
16,384 KB
testcase_49 AC 357 ms
16,512 KB
testcase_50 AC 349 ms
16,384 KB
testcase_51 AC 357 ms
16,512 KB
testcase_52 AC 368 ms
16,512 KB
testcase_53 AC 358 ms
16,256 KB
testcase_54 AC 357 ms
16,384 KB
testcase_55 AC 369 ms
16,384 KB
testcase_56 AC 366 ms
16,384 KB
testcase_57 AC 360 ms
16,512 KB
testcase_58 AC 356 ms
16,512 KB
testcase_59 AC 360 ms
16,512 KB
testcase_60 AC 358 ms
16,512 KB
testcase_61 AC 359 ms
16,512 KB
testcase_62 AC 359 ms
16,512 KB
testcase_63 AC 358 ms
16,512 KB
testcase_64 AC 360 ms
16,384 KB
testcase_65 AC 361 ms
16,384 KB
testcase_66 AC 112 ms
5,376 KB
testcase_67 AC 347 ms
14,848 KB
testcase_68 AC 358 ms
16,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io;

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 s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let v: Vec<_> = s.split_whitespace().collect();
    let mut a: Vec<i64> = vec![0; n];
    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;
    }

    for i in 0..q {
        l[i] -= 1;
        r[i] -= 1;
        l[i] = l[i].max(last[r[i]]);
        println!(
            "{}",
            ((a_sum[r[i] + 1] - a_sum[l[i] + 1] + MOD) * pow_half[l[i] + 1] + a[l[i]]) % MOD
        );
    }
}
0