-
Notifications
You must be signed in to change notification settings - Fork 1
/
Range_Affine_Range_Sum.test.cpp
67 lines (55 loc) · 1.22 KB
/
Range_Affine_Range_Sum.test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#define PROBLEM "https://judge.yosupo.jp/problem/range_affine_range_sum"
#include <iostream>
#include <vector>
#include "../../data_structure/lazysegtree.hpp"
#include "../../template/template.hpp"
#include "../../utility/modint.hpp"
using namespace lib;
using mint = modint998244353;
struct S {
mint a;
int size;
};
struct F {
mint a, b;
F(mint a, mint b) : a(a), b(b) {}
};
S op(S l, S r) {
return S{l.a + r.a, l.size + r.size};
}
S e() {
return S{0, 0};
}
S mapping(F l, S r) {
return S{r.a * l.a + (mint)r.size * l.b, r.size};
}
F composition(F l, F r) {
return F{r.a * l.a, r.b * l.a + l.b};
}
F id() {
return F{1, 0};
}
int main() {
int n, q;
std::cin >> n >> q;
std::vector<S> v(n);
for (int i = 0; i < n; i++) {
int a;
std::cin >> a;
v[i] = {a, 1};
}
lazysegtree<S, op, e, F, mapping, composition, id> seg(v);
while (q--) {
int t;
std::cin >> t;
if (t == 0) {
int l, r, b, c;
std::cin >> l >> r >> b >> c;
seg.apply(l, r, F(b, c));
} else {
int l, r;
std::cin >> l >> r;
std::cout << seg.prod(l, r).a.val() << std::endl;
}
}
}