結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 311 ms
12,672 KB
testcase_04 AC 143 ms
5,376 KB
testcase_05 AC 190 ms
7,680 KB
testcase_06 AC 205 ms
9,088 KB
testcase_07 AC 332 ms
10,240 KB
testcase_08 AC 21 ms
5,504 KB
testcase_09 AC 269 ms
6,656 KB
testcase_10 AC 41 ms
5,376 KB
testcase_11 AC 179 ms
7,552 KB
testcase_12 AC 441 ms
13,440 KB
testcase_13 AC 347 ms
13,312 KB
testcase_14 AC 313 ms
13,312 KB
testcase_15 AC 316 ms
13,312 KB
testcase_16 AC 329 ms
13,312 KB
testcase_17 AC 309 ms
13,312 KB
testcase_18 AC 316 ms
13,312 KB
testcase_19 AC 355 ms
13,312 KB
testcase_20 AC 346 ms
13,312 KB
testcase_21 AC 255 ms
5,376 KB
testcase_22 AC 264 ms
5,376 KB
testcase_23 AC 267 ms
5,376 KB
testcase_24 AC 264 ms
5,376 KB
testcase_25 AC 256 ms
5,376 KB
testcase_26 AC 267 ms
5,376 KB
testcase_27 AC 294 ms
5,376 KB
testcase_28 AC 260 ms
5,376 KB
testcase_29 AC 265 ms
5,376 KB
testcase_30 AC 310 ms
13,440 KB
testcase_31 AC 319 ms
13,440 KB
testcase_32 AC 306 ms
13,312 KB
testcase_33 AC 312 ms
13,312 KB
testcase_34 AC 309 ms
13,312 KB
testcase_35 AC 310 ms
13,312 KB
testcase_36 AC 315 ms
13,184 KB
testcase_37 AC 311 ms
13,312 KB
testcase_38 AC 323 ms
13,312 KB
testcase_39 AC 284 ms
5,376 KB
testcase_40 AC 265 ms
5,376 KB
testcase_41 AC 279 ms
5,376 KB
testcase_42 AC 262 ms
5,376 KB
testcase_43 AC 272 ms
5,376 KB
testcase_44 AC 266 ms
5,376 KB
testcase_45 AC 266 ms
5,376 KB
testcase_46 AC 274 ms
5,376 KB
testcase_47 AC 261 ms
5,376 KB
testcase_48 AC 314 ms
13,440 KB
testcase_49 AC 312 ms
13,312 KB
testcase_50 AC 296 ms
13,440 KB
testcase_51 AC 298 ms
13,440 KB
testcase_52 AC 318 ms
13,312 KB
testcase_53 AC 294 ms
13,440 KB
testcase_54 AC 303 ms
13,312 KB
testcase_55 AC 316 ms
13,312 KB
testcase_56 AC 299 ms
13,312 KB
testcase_57 AC 296 ms
13,312 KB
testcase_58 AC 300 ms
13,312 KB
testcase_59 AC 308 ms
13,440 KB
testcase_60 AC 313 ms
13,312 KB
testcase_61 AC 306 ms
13,312 KB
testcase_62 AC 302 ms
13,440 KB
testcase_63 AC 297 ms
13,312 KB
testcase_64 AC 332 ms
13,440 KB
testcase_65 AC 307 ms
13,312 KB
testcase_66 AC 97 ms
5,376 KB
testcase_67 AC 296 ms
11,776 KB
testcase_68 AC 296 ms
13,440 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 l: Vec<usize> = Vec::new();
    let mut r: Vec<usize> = Vec::new();
    for _ in 0..q {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        let v: Vec<_> = s.split_whitespace().collect();
        l.push(v[0].trim().parse().unwrap());
        r.push(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 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 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