Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- #include <atcoder/modint>
- #include <atcoder/lazysegtree>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- using vi = vector<int>;
- using mint = atcoder::modint998244353;
- using atcoder::lazy_segtree;
- using S = mint;
- struct F {
- mint prob;
- mint val;
- };
- S op(S a, S b) { return a + b; }
- S e() { return 0; }
- S mapping(F f, S a) { return (1 - f.prob) * a + f.prob * f.val; }
- F composition(F f, F g)
- {
- if (f.prob == 0)
- return g;
- if (g.prob == 0)
- return f;
- mint prob = 1 - (1 - f.prob) * (1 - g.prob);
- // mint val = f.prob * (1 - g.prob) * f.val + g.prob * g.val;
- mint punion = f.prob * g.prob;
- mint pall = f.prob + g.prob - punion;
- mint val = (f.prob - punion) / pall * f.val + g.prob / pall * g.val;
- return {prob, val};
- }
- F id() { return {0, 0}; }
- int main(int argc, char **argv)
- {
- ll n, m;
- cin >> n >> m;
- vector<mint> mv(n);
- int v;
- for (auto &x : mv)
- cin >> v, x = v;
- lazy_segtree<S, op, e, F, mapping, composition, id> seg(mv);
- for (int i = 0, l, r, x; i < m; ++i) {
- cin >> l >> r >> x;
- l -= 1;
- mint d = r - l;
- seg.apply(l, r, F{1 / d, mint(x)});
- }
- for (int i = 0; i < n; ++i)
- cout << seg.get(i).val() << " \n"[i == n - 1];
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement