結果

問題 No.2170 Left Addition Machine
ユーザー trineutrontrineutron
提出日時 2022-12-22 18:51:57
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 532 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 5,205 ms
コンパイル使用メモリ 251,584 KB
実行使用メモリ 7,176 KB
最終ジャッジ日時 2023-08-11 13:07:14
合計ジャッジ時間 41,957 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 453 ms
6,788 KB
testcase_04 AC 205 ms
4,380 KB
testcase_05 AC 285 ms
4,780 KB
testcase_06 AC 270 ms
5,336 KB
testcase_07 AC 428 ms
5,624 KB
testcase_08 AC 51 ms
4,572 KB
testcase_09 AC 366 ms
4,380 KB
testcase_10 AC 57 ms
4,376 KB
testcase_11 AC 197 ms
5,192 KB
testcase_12 AC 493 ms
7,040 KB
testcase_13 AC 497 ms
6,864 KB
testcase_14 AC 492 ms
6,976 KB
testcase_15 AC 495 ms
6,900 KB
testcase_16 AC 497 ms
6,944 KB
testcase_17 AC 493 ms
6,992 KB
testcase_18 AC 492 ms
6,980 KB
testcase_19 AC 486 ms
7,036 KB
testcase_20 AC 486 ms
6,976 KB
testcase_21 AC 356 ms
4,380 KB
testcase_22 AC 367 ms
4,380 KB
testcase_23 AC 366 ms
4,380 KB
testcase_24 AC 365 ms
4,384 KB
testcase_25 AC 365 ms
4,380 KB
testcase_26 AC 377 ms
4,376 KB
testcase_27 AC 363 ms
4,380 KB
testcase_28 AC 368 ms
4,376 KB
testcase_29 AC 368 ms
4,376 KB
testcase_30 AC 503 ms
6,900 KB
testcase_31 AC 492 ms
6,980 KB
testcase_32 AC 500 ms
6,992 KB
testcase_33 AC 496 ms
7,028 KB
testcase_34 AC 509 ms
6,988 KB
testcase_35 AC 492 ms
7,092 KB
testcase_36 AC 503 ms
6,868 KB
testcase_37 AC 492 ms
6,992 KB
testcase_38 AC 494 ms
6,860 KB
testcase_39 AC 366 ms
4,384 KB
testcase_40 AC 370 ms
4,376 KB
testcase_41 AC 365 ms
4,376 KB
testcase_42 AC 361 ms
4,380 KB
testcase_43 AC 356 ms
4,380 KB
testcase_44 AC 372 ms
4,376 KB
testcase_45 AC 382 ms
4,376 KB
testcase_46 AC 368 ms
4,380 KB
testcase_47 AC 370 ms
4,380 KB
testcase_48 AC 501 ms
6,976 KB
testcase_49 AC 493 ms
7,020 KB
testcase_50 AC 501 ms
7,044 KB
testcase_51 AC 494 ms
6,984 KB
testcase_52 AC 495 ms
6,976 KB
testcase_53 AC 485 ms
6,928 KB
testcase_54 AC 497 ms
6,868 KB
testcase_55 AC 497 ms
7,112 KB
testcase_56 AC 531 ms
6,920 KB
testcase_57 AC 501 ms
6,868 KB
testcase_58 AC 500 ms
7,104 KB
testcase_59 AC 509 ms
6,984 KB
testcase_60 AC 496 ms
7,176 KB
testcase_61 AC 514 ms
6,984 KB
testcase_62 AC 510 ms
6,992 KB
testcase_63 AC 503 ms
6,996 KB
testcase_64 AC 504 ms
6,980 KB
testcase_65 AC 496 ms
7,172 KB
testcase_66 AC 134 ms
4,380 KB
testcase_67 AC 480 ms
6,940 KB
testcase_68 AC 532 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main() {
    int n, q;
    cin >> n >> q;
    vector<int64_t> a(n);
    for (auto &&x : a) {
        cin >> x;
    }

    vector<int> last(n);
    for (int i = 1; i < n; i++) {
        if (a.at(i) > a.at(i - 1)) {
            last.at(i) = last.at(i - 1);
        } else {
            last.at(i) = i;
        }
    }

    vector<mint> s(n + 1), pow_2(n + 1);
    pow_2.at(0) = 1;
    for (int i = 0; i < n; i++) {
        s.at(i + 1) = s.at(i) + pow_2.at(i) * a.at(i);
        pow_2.at(i + 1) = pow_2.at(i) * 2;
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        l = max(l, last.at(r));
        cout << ((s.at(r + 1) - s.at(l + 1)) / pow_2.at(l + 1) + a.at(l)).val()
             << endl;
    }

    return 0;
}
0