結果

問題 No.2170 Left Addition Machine
ユーザー 👑 NachiaNachia
提出日時 2022-12-22 00:12:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,857 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 86,500 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-29 05:20:08
合計ジャッジ時間 10,733 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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-1) + 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