algo — C++23 日本語リファレンス GitHub

test/yosupo/data_structure/point_set_range_composite.test.cpp

AC · 最終更新 2026-10-23 · GitHub

問題: https://judge.yosupo.jp/problem/point_set_range_composite

依存するヘッダ(5)
実装
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/point_set_range_composite
#include <iostream>
#include <utility>
#include <vector>
#include "number_theory/modint.hpp"
#include "segtree/segment_tree.hpp"

using Mint = modint998;

int main(void) {
    int n, q;
    std::cin >> n >> q;
    std::vector<std::pair<Mint, Mint>> p(n);
    for (auto &[a, b] : p) std::cin >> a >> b;
    SegmentTree<Affine<Mint>> st(p);

    while (q--) {
        int c;
        std::cin >> c;
        if (c == 0) {
            int k, a, b;
            std::cin >> k >> a >> b;
            st.set(k, {a, b});
        } else {
            int l, r, x;
            std::cin >> l >> r >> x;
            auto p = st.prod(l, r);
            std::cout << (p.first * x + p.second) << '\n';
        }
    }

    return 0;
}