結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 287 ms
46,336 KB
testcase_22 AC 291 ms
46,208 KB
testcase_23 AC 295 ms
46,336 KB
testcase_24 AC 410 ms
46,208 KB
testcase_25 AC 296 ms
46,336 KB
testcase_26 AC 296 ms
46,208 KB
testcase_27 AC 289 ms
46,208 KB
testcase_28 AC 291 ms
46,336 KB
testcase_29 AC 298 ms
46,208 KB
testcase_30 AC 300 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) }; }
};

struct Segtree{
    int N, logN;
    vector<vector<F>> A;
    Segtree(const vector<F>& a){
        int n = a.size();
        N = 1; logN = 0;
        while(N < n){ N *= 2; logN++; }
        A.assign(logN+1, vector<F>(N, F()));
        rep(i,n) A[0][i] = a[i];
        rep(d,logN) rep(i,N) A[d+1][i] = A[d][i] + A[d][i^(1<<d)];
    }
    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