結果

問題 No.1891 Static Xor Range Composite Query
ユーザー suisensuisen
提出日時 2022-07-12 03:11:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 601 ms / 5,000 ms
コード長 1,544 bytes
コンパイル時間 1,199 ms
コンパイル使用メモリ 83,680 KB
実行使用メモリ 64,804 KB
最終ジャッジ日時 2023-09-05 01:39:52
合計ジャッジ時間 10,094 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 601 ms
64,724 KB
testcase_22 AC 593 ms
64,740 KB
testcase_23 AC 590 ms
64,752 KB
testcase_24 AC 592 ms
64,752 KB
testcase_25 AC 593 ms
64,760 KB
testcase_26 AC 599 ms
64,760 KB
testcase_27 AC 599 ms
64,728 KB
testcase_28 AC 590 ms
64,728 KB
testcase_29 AC 595 ms
64,736 KB
testcase_30 AC 592 ms
64,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

#include <atcoder/modint>

using mint = atcoder::modint998244353;

struct F {
    mint a, b;
    mint eval(mint x) const { return a * x + b; }
};
F compose(F f, F g) { return F{ g.a * f.a, g.a * f.b + g.b }; }
F id() { return F{ 1, 0 }; }

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] = compose(seg[2 * k + 0][s], seg[2 * k + 1][s]);
            seg[k][1 * siz + s] = compose(seg[2 * k + 1][s], seg[2 * k + 0][s]);
        }
    }
    while (q --> 0) {
        int l, r, p, x;
        std::cin >> l >> r >> p >> x;

        auto query = [&](auto query, int tl, int tr, int k, int bit) -> F {
            if (r <= tl or tr <= l) return id();
            if (l <= tl and tr <= r) return seg[k][p & (bit - 1)];
            bit >>= 1;
            const bool flip = p & bit;
            const int tm = (tl + tr) >> 1;
            F sl = query(query, tl, tm, 2 * k +     flip, bit);
            F sr = query(query, tm, tr, 2 * k + not flip, bit);
            return compose(sl, sr);
        };

        std::cout << query(query, 0, n, 1, n).eval(x).val() << '\n';
    }
    return 0;
}
0