Skip to the content.

:heavy_check_mark: test/point_set_range_composite.test.cpp

Depends on

Code

#define PROBLEM "https://judge.yosupo.jp/problem/point_set_range_composite"

#include <sys/types.h>  // for uint

#include <data_structure/segment_tree.hpp>  // for Segtree
#include <fastio/base.hpp>                  // for FASTIO, cin, cout
#include <fastio/char/write.hpp>            // for operator<<
#include <fastio/pair/read.hpp>             // for operator>>
#include <fastio/signed/read.hpp>           // for operator>>
#include <fastio/unsigned/read.hpp>         // for operator>>
#include <fastio/unsigned/write.hpp>        // for operator<<
#include <fastio/vector/read.hpp>           // for operator>>
#include <iterator>                         // for pair
#include <templates/macro/abbrev/endl.hpp>  // for endl
#include <templates/macro/abbrev/mp.hpp>    // for MP
#include <templates/macro/abbrev/ull.hpp>   // for ull
#include <templates/macro/mod.hpp>          // for MOD1
#include <templates/rep.hpp>                // for rep
#include <templates/template.hpp>
#include <type_traits>  // for __decay_and_strip
#include <utility>      // for pair, make_pair
#include <vector>       // for vector

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<pair<ull, ull>> a(n);
    cin >> a;
    SegmentTree<
        pair<ull, ull>,
        [](pair<ull, ull> a, pair<ull, ull> b) {
            return MP(a.first * b.first % MOD1, (a.second * b.first + b.second) % MOD1);
        },
        []() { return MP(1, 0); }>
        seg(a);
    rep(_, q) {
        uint T;
        ull l, r, x;
        cin >> T >> l >> r >> x;
        if (T == 0) {
            seg.set(l, {r, x});
        } else {
            auto res = seg(l, r);
            auto ans = (res.first * x + res.second) % MOD1;
            cout << ans << endl;
        }
    }
}
#line 1 "test/point_set_range_composite.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/point_set_range_composite"

#include <sys/types.h>  // for uint

#include <data_structure/segment_tree.hpp>  // for Segtree
#include <fastio/base.hpp>                  // for FASTIO, cin, cout
#include <fastio/char/write.hpp>            // for operator<<
#include <fastio/pair/read.hpp>             // for operator>>
#include <fastio/signed/read.hpp>           // for operator>>
#include <fastio/unsigned/read.hpp>         // for operator>>
#include <fastio/unsigned/write.hpp>        // for operator<<
#include <fastio/vector/read.hpp>           // for operator>>
#include <iterator>                         // for pair
#include <templates/macro/abbrev/endl.hpp>  // for endl
#include <templates/macro/abbrev/mp.hpp>    // for MP
#include <templates/macro/abbrev/ull.hpp>   // for ull
#include <templates/macro/mod.hpp>          // for MOD1
#include <templates/rep.hpp>                // for rep
#include <templates/template.hpp>
#include <type_traits>  // for __decay_and_strip
#include <utility>      // for pair, make_pair
#include <vector>       // for vector

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<pair<ull, ull>> a(n);
    cin >> a;
    SegmentTree<
        pair<ull, ull>,
        [](pair<ull, ull> a, pair<ull, ull> b) {
            return MP(a.first * b.first % MOD1, (a.second * b.first + b.second) % MOD1);
        },
        []() { return MP(1, 0); }>
        seg(a);
    rep(_, q) {
        uint T;
        ull l, r, x;
        cin >> T >> l >> r >> x;
        if (T == 0) {
            seg.set(l, {r, x});
        } else {
            auto res = seg(l, r);
            auto ans = (res.first * x + res.second) % MOD1;
            cout << ans << endl;
        }
    }
}

Test cases

Env Name Status Elapsed Memory
g++ example_00 :heavy_check_mark: AC 43 ms 4 MB
g++ max_random_00 :heavy_check_mark: AC 166 ms 70 MB
g++ max_random_01 :heavy_check_mark: AC 167 ms 70 MB
g++ max_random_02 :heavy_check_mark: AC 168 ms 70 MB
g++ max_random_03 :heavy_check_mark: AC 164 ms 70 MB
g++ max_random_04 :heavy_check_mark: AC 166 ms 70 MB
g++ random_00 :heavy_check_mark: AC 136 ms 64 MB
g++ random_01 :heavy_check_mark: AC 150 ms 66 MB
g++ random_02 :heavy_check_mark: AC 89 ms 22 MB
g++ random_03 :heavy_check_mark: AC 39 ms 54 MB
g++ random_04 :heavy_check_mark: AC 52 ms 51 MB
g++ small_00 :heavy_check_mark: AC 5 ms 4 MB
g++ small_01 :heavy_check_mark: AC 5 ms 4 MB
g++ small_02 :heavy_check_mark: AC 4 ms 4 MB
g++ small_03 :heavy_check_mark: AC 4 ms 4 MB
g++ small_04 :heavy_check_mark: AC 4 ms 4 MB
Back to top page