結果

問題 No.1891 Static Xor Range Composite Query
ユーザー suisensuisen
提出日時 2022-07-12 02:58:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 661 ms / 5,000 ms
コード長 1,838 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 80,832 KB
実行使用メモリ 64,936 KB
最終ジャッジ日時 2023-09-05 01:21:51
合計ジャッジ時間 13,787 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,512 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 4 ms
4,384 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,384 KB
testcase_16 AC 3 ms
4,384 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,384 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 658 ms
64,772 KB
testcase_22 AC 641 ms
64,936 KB
testcase_23 AC 650 ms
64,752 KB
testcase_24 AC 644 ms
64,768 KB
testcase_25 AC 630 ms
64,776 KB
testcase_26 AC 631 ms
64,764 KB
testcase_27 AC 634 ms
64,764 KB
testcase_28 AC 661 ms
64,760 KB
testcase_29 AC 639 ms
64,836 KB
testcase_30 AC 636 ms
64,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

#include <atcoder/modint>

using mint = atcoder::modint998244353;

struct F {
    mint a, b;
    static F op(F f, F g) {
        return F{ g.a * f.a, g.a * f.b + g.b };
    }
    static F e() {
        return F{ 1, 0 };
    }
    mint eval(mint x) {
        return a * x + b;
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, q;
    std::cin >> n >> q;

    std::vector<std::vector<F>> seg(2 * n);
    for (int i = 0; i < n; ++i) {
        int a, b;
        std::cin >> a >> b;
        seg[n + i] = { F { a, b } };
    }
    for (int k = n - 1; k >= 1; --k) {
        const int siz = seg[2 * k].size();
        seg[k].resize(2 * siz);
        for (int s = 0; s < siz; ++s) {
            seg[k][0 * siz + s] = F::op(seg[2 * k + 0][s], seg[2 * k + 1][s]);
            seg[k][1 * siz + s] = F::op(seg[2 * k + 1][s], seg[2 * k + 0][s]);
        }
    }
    auto query = [&](auto query, int ql, int qr, int tl, int tr, int k, int p, int bit) -> F {
        if (qr <= tl or tr <= ql) return F::e();
        if (ql <= tl and tr <= qr) return seg[k][p];
        const int flip = p & bit;
        const int tm = (tl + tr) >> 1;
        if (flip) {
            F sl = query(query, ql, qr, tl, tm, 2 * k + 1, p ^ flip, bit >> 1);
            F sr = query(query, ql, qr, tm, tr, 2 * k + 0, p ^ flip, bit >> 1);
            return F::op(sl, sr);
        } else {
            F sl = query(query, ql, qr, tl, tm, 2 * k + 0, p ^ flip, bit >> 1);
            F sr = query(query, ql, qr, tm, tr, 2 * k + 1, p ^ flip, bit >> 1);
            return F::op(sl, sr);
        }
    };
    while (q --> 0) {
        int l, r, p, x;
        std::cin >> l >> r >> p >> x;
        std::cout << query(query, l, r, 0, n, 1, p, n >> 1).eval(x).val() << '\n';
    }
    return 0;
}
0