結果

問題 No.2170 Left Addition Machine
ユーザー trineutrontrineutron
提出日時 2022-12-22 21:52:26
言語 Rust
(1.77.0)
結果
AC  
実行時間 433 ms / 2,000 ms
コード長 1,608 bytes
コンパイル時間 15,215 ms
コンパイル使用メモリ 378,360 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2024-04-29 05:37:01
合計ジャッジ時間 46,652 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 433 ms
9,856 KB
testcase_04 AC 165 ms
5,376 KB
testcase_05 AC 226 ms
5,504 KB
testcase_06 AC 199 ms
7,168 KB
testcase_07 AC 324 ms
7,424 KB
testcase_08 AC 24 ms
5,504 KB
testcase_09 AC 286 ms
5,376 KB
testcase_10 AC 45 ms
5,376 KB
testcase_11 AC 148 ms
6,272 KB
testcase_12 AC 369 ms
10,112 KB
testcase_13 AC 369 ms
9,984 KB
testcase_14 AC 363 ms
10,112 KB
testcase_15 AC 361 ms
10,112 KB
testcase_16 AC 383 ms
10,112 KB
testcase_17 AC 375 ms
10,112 KB
testcase_18 AC 381 ms
10,112 KB
testcase_19 AC 370 ms
9,984 KB
testcase_20 AC 369 ms
10,112 KB
testcase_21 AC 298 ms
5,376 KB
testcase_22 AC 296 ms
5,376 KB
testcase_23 AC 296 ms
5,376 KB
testcase_24 AC 297 ms
5,376 KB
testcase_25 AC 291 ms
5,376 KB
testcase_26 AC 292 ms
5,376 KB
testcase_27 AC 295 ms
5,376 KB
testcase_28 AC 297 ms
5,376 KB
testcase_29 AC 297 ms
5,376 KB
testcase_30 AC 376 ms
10,240 KB
testcase_31 AC 369 ms
10,112 KB
testcase_32 AC 373 ms
10,240 KB
testcase_33 AC 366 ms
10,112 KB
testcase_34 AC 365 ms
10,112 KB
testcase_35 AC 364 ms
10,112 KB
testcase_36 AC 366 ms
10,112 KB
testcase_37 AC 377 ms
10,112 KB
testcase_38 AC 367 ms
10,112 KB
testcase_39 AC 298 ms
5,376 KB
testcase_40 AC 303 ms
5,376 KB
testcase_41 AC 300 ms
5,376 KB
testcase_42 AC 296 ms
5,376 KB
testcase_43 AC 294 ms
5,376 KB
testcase_44 AC 294 ms
5,376 KB
testcase_45 AC 295 ms
5,376 KB
testcase_46 AC 289 ms
5,376 KB
testcase_47 AC 292 ms
5,376 KB
testcase_48 AC 355 ms
10,112 KB
testcase_49 AC 352 ms
10,112 KB
testcase_50 AC 349 ms
10,112 KB
testcase_51 AC 354 ms
10,112 KB
testcase_52 AC 357 ms
10,112 KB
testcase_53 AC 343 ms
10,112 KB
testcase_54 AC 364 ms
10,240 KB
testcase_55 AC 357 ms
10,240 KB
testcase_56 AC 365 ms
10,112 KB
testcase_57 AC 354 ms
10,368 KB
testcase_58 AC 355 ms
10,240 KB
testcase_59 AC 352 ms
10,240 KB
testcase_60 AC 355 ms
10,112 KB
testcase_61 AC 357 ms
10,240 KB
testcase_62 AC 357 ms
10,240 KB
testcase_63 AC 364 ms
10,240 KB
testcase_64 AC 355 ms
10,240 KB
testcase_65 AC 358 ms
10,240 KB
testcase_66 AC 112 ms
5,376 KB
testcase_67 AC 350 ms
8,576 KB
testcase_68 AC 357 ms
10,240 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 = s.split_whitespace();
    let mut a: Vec<i64> = Vec::new();
    for x in v {
        a.push(x.trim().parse().unwrap());
    }
    let a = a;

    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 last = last;

    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 a_sum = a_sum;
    let pow_half = pow_half;

    for _ in 0..q {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        let v: Vec<_> = s.split_whitespace().collect();
        let mut l: usize = v[0].trim().parse().unwrap();
        let mut r: usize = v[1].trim().parse().unwrap();
        l -= 1;
        r -= 1;
        l = l.max(last[r]);
        let l = l;
        let r = r;
        println!(
            "{}",
            ((a_sum[r + 1] - a_sum[l + 1] + MOD) * pow_half[l + 1] + a[l]) % MOD
        );
    }
}
0