Advertisement
pb_jiang

ABC332F WA

Dec 11th, 2023
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. #include <atcoder/modint>
  4. #include <atcoder/lazysegtree>
  5. using namespace std;
  6. #ifndef __DEBUG__
  7. #define dbg(...) 42
  8. #endif
  9. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  10.  
  11. using ll = long long;
  12. using pii = pair<int, int>;
  13. using pll = pair<ll, ll>;
  14. using vl = vector<ll>;
  15. using vi = vector<int>;
  16. using mint = atcoder::modint998244353;
  17. using atcoder::lazy_segtree;
  18.  
  19. using S = mint;
  20. struct F {
  21.     mint prob;
  22.     mint val;
  23. };
  24. S op(S a, S b) { return a + b; }
  25. S e() { return 0; }
  26. S mapping(F f, S a) { return (1 - f.prob) * a + f.prob * f.val; }
  27. F composition(F f, F g)
  28. {
  29.     if (f.prob == 0)
  30.         return g;
  31.     if (g.prob == 0)
  32.         return f;
  33.     mint prob = 1 - (1 - f.prob) * (1 - g.prob);
  34.     // mint val = f.prob * (1 - g.prob) * f.val + g.prob * g.val;
  35.     mint punion = f.prob * g.prob;
  36.     mint pall = f.prob + g.prob - punion;
  37.     mint val = (f.prob - punion) / pall * f.val + g.prob / pall * g.val;
  38.     return {prob, val};
  39. }
  40. F id() { return {0, 0}; }
  41.  
  42. int main(int argc, char **argv)
  43. {
  44.     ll n, m;
  45.     cin >> n >> m;
  46.     vector<mint> mv(n);
  47.     int v;
  48.     for (auto &x : mv)
  49.         cin >> v, x = v;
  50.     lazy_segtree<S, op, e, F, mapping, composition, id> seg(mv);
  51.     for (int i = 0, l, r, x; i < m; ++i) {
  52.         cin >> l >> r >> x;
  53.         l -= 1;
  54.         mint d = r - l;
  55.         seg.apply(l, r, F{1 / d, mint(x)});
  56.     }
  57.     for (int i = 0; i < n; ++i)
  58.         cout << seg.get(i).val() << " \n"[i == n - 1];
  59.     return 0;
  60. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement