結果

問題 No.2170 Left Addition Machine
ユーザー trineutrontrineutron
提出日時 2022-12-22 22:13:32
言語 Rust
(1.77.0)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 1,593 bytes
コンパイル時間 11,487 ms
コンパイル使用メモリ 386,436 KB
実行使用メモリ 25,344 KB
最終ジャッジ日時 2024-04-29 05:37:43
合計ジャッジ時間 38,341 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 314 ms
23,424 KB
testcase_04 AC 143 ms
8,448 KB
testcase_05 AC 186 ms
14,336 KB
testcase_06 AC 177 ms
15,744 KB
testcase_07 AC 278 ms
20,096 KB
testcase_08 AC 24 ms
7,296 KB
testcase_09 AC 274 ms
14,720 KB
testcase_10 AC 38 ms
5,376 KB
testcase_11 AC 142 ms
12,672 KB
testcase_12 AC 336 ms
25,344 KB
testcase_13 AC 355 ms
25,216 KB
testcase_14 AC 357 ms
25,216 KB
testcase_15 AC 312 ms
25,344 KB
testcase_16 AC 327 ms
25,344 KB
testcase_17 AC 357 ms
25,344 KB
testcase_18 AC 370 ms
25,216 KB
testcase_19 AC 295 ms
25,344 KB
testcase_20 AC 325 ms
25,344 KB
testcase_21 AC 250 ms
12,928 KB
testcase_22 AC 267 ms
12,928 KB
testcase_23 AC 272 ms
12,800 KB
testcase_24 AC 284 ms
12,928 KB
testcase_25 AC 272 ms
12,800 KB
testcase_26 AC 280 ms
12,800 KB
testcase_27 AC 282 ms
12,800 KB
testcase_28 AC 280 ms
12,928 KB
testcase_29 AC 275 ms
12,800 KB
testcase_30 AC 370 ms
25,088 KB
testcase_31 AC 356 ms
25,344 KB
testcase_32 AC 301 ms
25,344 KB
testcase_33 AC 300 ms
25,216 KB
testcase_34 AC 357 ms
25,216 KB
testcase_35 AC 341 ms
25,216 KB
testcase_36 AC 349 ms
25,344 KB
testcase_37 AC 360 ms
25,216 KB
testcase_38 AC 333 ms
25,216 KB
testcase_39 AC 254 ms
12,928 KB
testcase_40 AC 266 ms
12,800 KB
testcase_41 AC 247 ms
12,928 KB
testcase_42 AC 277 ms
12,928 KB
testcase_43 AC 289 ms
12,928 KB
testcase_44 AC 278 ms
12,800 KB
testcase_45 AC 243 ms
12,928 KB
testcase_46 AC 243 ms
12,800 KB
testcase_47 AC 263 ms
12,800 KB
testcase_48 AC 290 ms
25,216 KB
testcase_49 AC 303 ms
25,216 KB
testcase_50 AC 292 ms
25,216 KB
testcase_51 AC 293 ms
25,216 KB
testcase_52 AC 274 ms
25,216 KB
testcase_53 AC 285 ms
25,216 KB
testcase_54 AC 287 ms
25,344 KB
testcase_55 AC 294 ms
25,344 KB
testcase_56 AC 302 ms
25,216 KB
testcase_57 AC 296 ms
25,216 KB
testcase_58 AC 285 ms
25,280 KB
testcase_59 AC 291 ms
25,216 KB
testcase_60 AC 287 ms
25,344 KB
testcase_61 AC 287 ms
25,216 KB
testcase_62 AC 285 ms
25,216 KB
testcase_63 AC 317 ms
25,216 KB
testcase_64 AC 303 ms
25,344 KB
testcase_65 AC 283 ms
25,216 KB
testcase_66 AC 93 ms
5,888 KB
testcase_67 AC 278 ms
23,808 KB
testcase_68 AC 287 ms
25,216 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];
    let s = io::read_to_string(io::stdin()).unwrap();
    let v: Vec<_> = s.split_whitespace().collect();
    for i in 0..q {
        l[i] = v[2 * i].trim().parse().unwrap();
        r[i] = v[2 * i + 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