結果

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

ソースコード

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