結果

問題 No.1891 Static Xor Range Composite Query
ユーザー 👑 NachiaNachia
提出日時 2022-04-04 18:39:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 272 ms / 5,000 ms
コード長 1,723 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 87,660 KB
実行使用メモリ 46,336 KB
最終ジャッジ日時 2024-05-04 04:07:20
合計ジャッジ時間 6,701 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 265 ms
46,208 KB
testcase_22 AC 270 ms
46,336 KB
testcase_23 AC 268 ms
46,336 KB
testcase_24 AC 270 ms
46,336 KB
testcase_25 AC 257 ms
46,336 KB
testcase_26 AC 272 ms
46,336 KB
testcase_27 AC 259 ms
46,336 KB
testcase_28 AC 259 ms
46,208 KB
testcase_29 AC 264 ms
46,208 KB
testcase_30 AC 261 ms
46,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


const u32 MOD = 998244353;

struct F{
    u32 a=1, b=0;
    u32 operator()(u32 x){ return ((u64)a*x + b) % MOD; }
    F operator+(F r){ return { (u32)(((u64)a*r.a) % MOD), (u32)(((u64)b*r.a+r.b) % MOD) }; }
};

#include <tuple>

struct Segtree{
    int N, logN;
    vector<vector<F>> A;
    Segtree(vector<F> a){
        int n = a.size();
        N = 1; logN = 0;
        while(N < n){ N *= 2; logN++; }
        A.resize(logN+1);
        A[0] = a;
        A[0].resize(N);
        rep(d,logN){
            auto tmp = A[d];
            rep(i,N) if((i&(1<<d)) == 0){
                tie(tmp[i], tmp[i|(1<<d)]) = make_pair(
                    tmp[i] + tmp[i|(1<<d)],
                    tmp[i|(1<<d)] + tmp[i]
                );
            }
            A[d+1] = move(tmp);
        }
    }
    F prod(int l, int r, int x){
        F ql, qr;
        int d = 0;
        while(l < r){
            if(l & 1){ ql = ql + A[d][(l<<d)^x]; l++; }
            if(r & 1){ r--; qr = A[d][(r<<d)^x] + qr; }
            l /= 2; r /= 2; d++;
        }
        return ql + qr;
    }
};

int main(){
    int N, Q; cin >> N >> Q;
    vector<F> A(N);
    rep(i,N) cin >> A[i].a >> A[i].b;
    Segtree rq(A);
    rep(i,Q){
        int l,r,p; u32 x; cin >> l >> r >> p >> x;
        u32 ans = rq.prod(l,r,p)(x);
        cout << ans << '\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