結果

問題 No.2170 Left Addition Machine
ユーザー 👑 NachiaNachia
提出日時 2022-12-22 00:15:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 3,857 bytes
コンパイル時間 1,189 ms
コンパイル使用メモリ 86,124 KB
実行使用メモリ 6,356 KB
最終ジャッジ日時 2023-08-11 12:56:28
合計ジャッジ時間 14,113 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 71 ms
6,136 KB
testcase_04 AC 26 ms
4,380 KB
testcase_05 AC 42 ms
4,380 KB
testcase_06 AC 45 ms
5,092 KB
testcase_07 AC 63 ms
5,088 KB
testcase_08 AC 15 ms
4,380 KB
testcase_09 AC 49 ms
4,380 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 36 ms
4,720 KB
testcase_12 AC 81 ms
6,208 KB
testcase_13 AC 78 ms
6,128 KB
testcase_14 AC 80 ms
6,112 KB
testcase_15 AC 79 ms
6,356 KB
testcase_16 AC 80 ms
6,200 KB
testcase_17 AC 81 ms
6,108 KB
testcase_18 AC 79 ms
6,144 KB
testcase_19 AC 77 ms
6,168 KB
testcase_20 AC 80 ms
6,160 KB
testcase_21 AC 42 ms
4,380 KB
testcase_22 AC 41 ms
4,376 KB
testcase_23 AC 41 ms
4,380 KB
testcase_24 AC 41 ms
4,384 KB
testcase_25 AC 42 ms
4,376 KB
testcase_26 AC 43 ms
4,376 KB
testcase_27 AC 42 ms
4,380 KB
testcase_28 AC 42 ms
4,380 KB
testcase_29 AC 42 ms
4,376 KB
testcase_30 AC 79 ms
6,088 KB
testcase_31 AC 81 ms
6,108 KB
testcase_32 AC 83 ms
6,144 KB
testcase_33 AC 83 ms
6,152 KB
testcase_34 AC 80 ms
6,156 KB
testcase_35 AC 78 ms
6,236 KB
testcase_36 AC 79 ms
6,132 KB
testcase_37 AC 80 ms
6,156 KB
testcase_38 AC 86 ms
6,124 KB
testcase_39 AC 44 ms
4,380 KB
testcase_40 AC 43 ms
4,384 KB
testcase_41 AC 42 ms
4,508 KB
testcase_42 AC 47 ms
4,924 KB
testcase_43 AC 42 ms
4,732 KB
testcase_44 AC 44 ms
4,920 KB
testcase_45 AC 42 ms
4,920 KB
testcase_46 AC 43 ms
4,376 KB
testcase_47 AC 42 ms
4,376 KB
testcase_48 AC 81 ms
6,220 KB
testcase_49 AC 79 ms
6,176 KB
testcase_50 AC 80 ms
6,160 KB
testcase_51 AC 82 ms
6,156 KB
testcase_52 AC 82 ms
6,128 KB
testcase_53 AC 80 ms
6,152 KB
testcase_54 AC 80 ms
6,192 KB
testcase_55 AC 82 ms
6,148 KB
testcase_56 AC 83 ms
6,224 KB
testcase_57 AC 79 ms
6,200 KB
testcase_58 AC 79 ms
6,132 KB
testcase_59 AC 79 ms
6,160 KB
testcase_60 AC 78 ms
6,104 KB
testcase_61 AC 78 ms
6,196 KB
testcase_62 AC 80 ms
6,336 KB
testcase_63 AC 81 ms
6,092 KB
testcase_64 AC 79 ms
6,084 KB
testcase_65 AC 77 ms
6,084 KB
testcase_66 AC 15 ms
4,928 KB
testcase_67 AC 69 ms
6,156 KB
testcase_68 AC 77 ms
6,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "Main.cpp"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <atcoder/modint>
#line 2 "nachia\\set\\word-size-tree.hpp"

#line 5 "nachia\\set\\word-size-tree.hpp"

namespace nachia{

struct WordsizeTree{
    using Word = unsigned long long;
    static constexpr unsigned int W = 64;
    int N;
    std::vector<std::vector<Word>> A;
    static int highBit(Word x){
        if(x == 0) return 0;
        return W-1 - __builtin_clzll(x);
    }
    static int lowBit(Word x){
        if(x == 0) return W;
        return __builtin_ctzll(x);
    }
    WordsizeTree(unsigned int length){
        N = length;
        int n = length;
        do {
            std::vector<Word> a(n/W+1,0);
            A.emplace_back(std::move(a));
            n /= W;
        } while(n);
    }
    WordsizeTree(const std::string& binStr = ""){
        N = binStr.size();
        int n = N;
        {
            std::vector<Word> a(n/W+1);
            for(int i=0; i<n; i++) if(binStr[i] == '1'){
                a[i/W] |= (Word)1 << (i%W);
            }
            A.emplace_back(std::move(a));
            n /= W;
        }
        while(n){
            std::vector<Word> a(n/W+1,0);
            for(int i=0; i<=n; i++){
                if(A.back()[i]) a[i/W] |= (Word)1 << (i%W);
            }
            A.emplace_back(std::move(a));
            n /= W;
        }
    }
    void insert(int x){
        for(auto& a : A){
            a[x/W] |= (Word)1 << (x % W);
            x /= W;
        }
    }
    void erase(int x){
        for(auto& a : A){
        a[x/W] &= ~((Word)1 << (x % W));
        if(a[x/W]) return;
        x /= W;
        }
    }
    int count(int x) const {
        return (int)((A[0][x/W] >> (x%W)) & 1);
    }
    int noLessThan(int x) const {
        int d = 0, i = x;
        while(true){
            if(d >= (int)A.size()) return -1;
            if(i/W >= (int)A[d].size()) return -1;
            Word m = A[d][i/W] & ((~(Word)0) << (i%W));
            if(!m){ d++; i /= W; i++; }
            else{
                int to = lowBit(m);
                i = i/W*W + to;
                if(d == 0) break;
                i *= W;
                d--;
            }
        }
        return i;
    }
    int noGreaterThan(int x) const {
        int d = 0, i = x;
        while(true){
            if(i < 0) return -1;
            if(d >= (int)A.size()) return -1;
            Word m = A[d][i/W] & ~((~(Word)1) << (i%W));
            if(!m){ d++; i /= W; i--; }
            else{
                int to = highBit(m);
                i = i/W*W + to;
                if(d == 0) break;
                i *= W;
                i += W-1;
                d--;
            }
        }
        return i;
    }
};

} // namespace nachia
#line 8 "Main.cpp"

using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;



int main(){
    int N, Q; cin >> N >> Q;
    vector<int> A(N); rep(i,N) cin >> A[i];
    vector<Modint> B(N); rep(i,N) B[i] = Modint::raw(A[i]);
    vector<Modint> sumB(N+1);
    for(int i=N-1; i>=0; i--) sumB[i] = sumB[i+1] + sumB[i+1] + B[i];
    vector<Modint> pow2(N+1);
    pow2[0] = 1;
    for(int i=1; i<=N; i++) pow2[i] = pow2[i-1] + pow2[i-1];
    nachia::WordsizeTree S(N);
    rep(i,N-1) if(A[i] >= A[i+1]) S.insert(i);
    rep(i,Q){
        int l, r; cin >> l >> r; l--;
        l = max(l, S.noGreaterThan(r-2) + 1);
        Modint ans = sumB[l+1] - sumB[r] * pow2[r-l-1] + B[l];
        cout << ans.val() << '\n';
    }
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


0