結果

問題 No.2170 Left Addition Machine
ユーザー milanis48663220milanis48663220
提出日時 2023-07-08 01:47:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 435 ms / 2,000 ms
コード長 2,639 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 123,504 KB
実行使用メモリ 7,860 KB
最終ジャッジ日時 2023-09-29 03:21:09
合計ジャッジ時間 48,529 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 379 ms
7,468 KB
testcase_04 AC 187 ms
4,376 KB
testcase_05 AC 249 ms
5,148 KB
testcase_06 AC 237 ms
5,812 KB
testcase_07 AC 366 ms
6,076 KB
testcase_08 AC 36 ms
4,940 KB
testcase_09 AC 324 ms
4,380 KB
testcase_10 AC 50 ms
4,380 KB
testcase_11 AC 172 ms
5,284 KB
testcase_12 AC 424 ms
7,732 KB
testcase_13 AC 419 ms
7,696 KB
testcase_14 AC 419 ms
7,724 KB
testcase_15 AC 424 ms
7,732 KB
testcase_16 AC 426 ms
7,728 KB
testcase_17 AC 426 ms
7,724 KB
testcase_18 AC 419 ms
7,724 KB
testcase_19 AC 421 ms
7,740 KB
testcase_20 AC 433 ms
7,848 KB
testcase_21 AC 333 ms
4,376 KB
testcase_22 AC 331 ms
4,376 KB
testcase_23 AC 331 ms
4,376 KB
testcase_24 AC 331 ms
4,380 KB
testcase_25 AC 330 ms
4,376 KB
testcase_26 AC 335 ms
4,376 KB
testcase_27 AC 337 ms
4,384 KB
testcase_28 AC 331 ms
4,380 KB
testcase_29 AC 336 ms
4,376 KB
testcase_30 AC 426 ms
7,704 KB
testcase_31 AC 422 ms
7,724 KB
testcase_32 AC 419 ms
7,796 KB
testcase_33 AC 422 ms
7,724 KB
testcase_34 AC 421 ms
7,668 KB
testcase_35 AC 426 ms
7,724 KB
testcase_36 AC 427 ms
7,660 KB
testcase_37 AC 431 ms
7,700 KB
testcase_38 AC 430 ms
7,736 KB
testcase_39 AC 335 ms
4,376 KB
testcase_40 AC 332 ms
4,380 KB
testcase_41 AC 328 ms
4,384 KB
testcase_42 AC 334 ms
4,380 KB
testcase_43 AC 337 ms
4,376 KB
testcase_44 AC 330 ms
4,376 KB
testcase_45 AC 334 ms
4,376 KB
testcase_46 AC 331 ms
4,380 KB
testcase_47 AC 334 ms
4,380 KB
testcase_48 AC 429 ms
7,724 KB
testcase_49 AC 423 ms
7,752 KB
testcase_50 AC 431 ms
7,752 KB
testcase_51 AC 425 ms
7,656 KB
testcase_52 AC 419 ms
7,672 KB
testcase_53 AC 416 ms
7,728 KB
testcase_54 AC 425 ms
7,728 KB
testcase_55 AC 435 ms
7,860 KB
testcase_56 AC 421 ms
7,664 KB
testcase_57 AC 420 ms
7,732 KB
testcase_58 AC 420 ms
7,676 KB
testcase_59 AC 428 ms
7,728 KB
testcase_60 AC 427 ms
7,652 KB
testcase_61 AC 418 ms
7,740 KB
testcase_62 AC 411 ms
7,660 KB
testcase_63 AC 408 ms
7,724 KB
testcase_64 AC 411 ms
7,740 KB
testcase_65 AC 413 ms
7,728 KB
testcase_66 AC 121 ms
4,992 KB
testcase_67 AC 402 ms
7,732 KB
testcase_68 AC 420 ms
7,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using mint = atcoder::modint998244353;

ostream& operator<<(ostream& os, const mint& m){
    os << m.val();
    return os;
}

template<typename T>
class Cumsum{
    public:
    Cumsum(vector<T> v): v(v){
        n = v.size();
        v_cumsum = vector<T>(n+1, T(0));
        for(int i = 0; i < n; i++) v_cumsum[i+1] = v_cumsum[i]+v[i];
    }
    /**
     * v[l] + ... + v[r-1]
     */ 
    T sum(int l, int r){
        if(r <= l) return T(0);
        if(r > n) r = n;
        if(l < 0) l = 0;
        return v_cumsum[r]-v_cumsum[l];
    }
    private:
    int n;
    vector<T> v;
    vector<T> v_cumsum;
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, q; cin >> n >> q;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int last = -1;
    vector<int> pre(n);
    pre[0] = -1;
    for(int i = 1; i < n; i++){
        if(a[i-1] >= a[i]){
            last = i-1;
        }
        pre[i] = last;
    }
    vector<mint> v(n);
    for(int i = 0; i < n; i++) {
        v[i] = a[i]*mint(2).pow(i);
    }
    auto cumsum = Cumsum<mint>(v);
    while(q--){
        int l, r; cin >> l >> r; l--; r--;
        int l0 = max(l, pre[r]+1);
        mint ans = a[l0];
        ans += cumsum.sum(l0+1, r+1)/mint(2).pow(l0+1);
        // for(int i = l0+1; i <= r; i++){
        //     ans += a[i]*mint(2).pow(i-l0-1);
        // }
        cout << ans << endl;
    }
}
0