結果

問題 No.2170 Left Addition Machine
ユーザー trineutrontrineutron
提出日時 2022-12-22 19:01:43
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 986 bytes
コンパイル時間 2,812 ms
コンパイル使用メモリ 249,716 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-29 05:33:14
合計ジャッジ時間 14,334 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 73 ms
6,272 KB
testcase_04 AC 24 ms
5,376 KB
testcase_05 AC 47 ms
5,376 KB
testcase_06 AC 52 ms
5,376 KB
testcase_07 AC 72 ms
5,376 KB
testcase_08 AC 15 ms
5,376 KB
testcase_09 AC 50 ms
5,376 KB
testcase_10 AC 9 ms
5,376 KB
testcase_11 AC 40 ms
5,376 KB
testcase_12 AC 108 ms
6,272 KB
testcase_13 AC 87 ms
6,400 KB
testcase_14 AC 88 ms
6,400 KB
testcase_15 AC 79 ms
6,528 KB
testcase_16 AC 77 ms
6,400 KB
testcase_17 AC 80 ms
6,400 KB
testcase_18 AC 82 ms
6,400 KB
testcase_19 AC 80 ms
6,400 KB
testcase_20 AC 79 ms
6,400 KB
testcase_21 AC 37 ms
5,376 KB
testcase_22 AC 43 ms
5,376 KB
testcase_23 AC 38 ms
5,376 KB
testcase_24 AC 37 ms
5,376 KB
testcase_25 AC 39 ms
5,376 KB
testcase_26 AC 39 ms
5,376 KB
testcase_27 AC 38 ms
5,376 KB
testcase_28 AC 39 ms
5,376 KB
testcase_29 AC 39 ms
5,376 KB
testcase_30 AC 75 ms
6,400 KB
testcase_31 AC 76 ms
6,400 KB
testcase_32 AC 75 ms
6,528 KB
testcase_33 AC 73 ms
6,400 KB
testcase_34 AC 74 ms
6,272 KB
testcase_35 AC 72 ms
6,528 KB
testcase_36 AC 74 ms
6,272 KB
testcase_37 AC 75 ms
6,528 KB
testcase_38 AC 80 ms
6,400 KB
testcase_39 AC 41 ms
5,376 KB
testcase_40 AC 42 ms
5,376 KB
testcase_41 AC 39 ms
5,376 KB
testcase_42 AC 39 ms
5,376 KB
testcase_43 AC 40 ms
5,376 KB
testcase_44 AC 42 ms
5,376 KB
testcase_45 AC 40 ms
5,376 KB
testcase_46 AC 38 ms
5,376 KB
testcase_47 AC 40 ms
5,376 KB
testcase_48 AC 77 ms
6,400 KB
testcase_49 AC 81 ms
6,528 KB
testcase_50 AC 82 ms
6,400 KB
testcase_51 AC 77 ms
6,400 KB
testcase_52 AC 77 ms
6,400 KB
testcase_53 AC 80 ms
6,528 KB
testcase_54 AC 76 ms
6,272 KB
testcase_55 AC 73 ms
6,400 KB
testcase_56 AC 77 ms
6,400 KB
testcase_57 AC 79 ms
6,400 KB
testcase_58 AC 74 ms
6,400 KB
testcase_59 AC 78 ms
6,400 KB
testcase_60 AC 82 ms
6,400 KB
testcase_61 AC 74 ms
6,528 KB
testcase_62 AC 76 ms
6,400 KB
testcase_63 AC 77 ms
6,528 KB
testcase_64 AC 77 ms
6,528 KB
testcase_65 AC 75 ms
6,400 KB
testcase_66 AC 14 ms
5,376 KB
testcase_67 AC 64 ms
6,272 KB
testcase_68 AC 76 ms
6,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

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

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

    const mint half = mint(1) / 2;

    vector<mint> s(n + 1), pow_half(n + 1);
    mint mul = 1;
    pow_half[0] = 1;
    for (int i = 0; i < n; i++) {
        s[i + 1] = s[i] + mul * a[i];
        mul += mul;
        pow_half[i + 1] = pow_half[i] * half;
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        l = max(l, last[r]);
        cout << ((s[r + 1] - s[l + 1]) * pow_half[l + 1] + a[l]).val() << '\n';
    }

    return 0;
}
0