結果

問題 No.2170 Left Addition Machine
ユーザー trineutron
提出日時 2022-12-22 19:00:03
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 3,157 ms
コンパイル使用メモリ 252,344 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-11-18 06:24:44
合計ジャッジ時間 16,601 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 69
権限があれば一括ダウンロードができます

ソースコード

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<int64_t> 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