Advertisement
pb_jiang

ABC276F wa

Nov 6th, 2022
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. #include <atcoder/segtree>
  4. #include <atcoder/modint>
  5. using namespace std;
  6. #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
  7. template <typename... Args> void logger(string vars, Args &&... values)
  8. {
  9.     cerr << vars << " = ";
  10.     string delim = "";
  11.     (..., (cerr << delim << values, delim = ", "));
  12.     cerr << endl;
  13. }
  14.  
  15. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  16. using ll = long long;
  17. using pii = pair<int, int>;
  18. using atcoder::segtree;
  19. using mint = atcoder::modint998244353;
  20.  
  21. const ll p = 998244353;
  22. ll n;
  23. ll arr[200003];
  24.  
  25. struct S {
  26.     mint val, cnt, sum;
  27. };
  28. S op(S a, S b) { return {0, a.cnt + b.cnt, a.sum + b.sum}; }
  29. S e() { return {0, 0, 0}; }
  30.  
  31. int main(int argc, char **argv)
  32. {
  33.     vector<ll> uniq;
  34.     cin >> n;
  35.     for (int i = 1; i <= n; ++i)
  36.         cin >> arr[i], uniq.push_back(arr[i]);
  37.     sort(uniq.begin(), uniq.end());
  38.     uniq.erase(unique(uniq.begin(), uniq.end()), uniq.end());
  39.  
  40.     int tlen = uniq.size();
  41.     segtree<S, op, e> seg(tlen);
  42.     mint prev_expect = arr[1];
  43.     {
  44.         cout << prev_expect.val() << endl;
  45.         int lb = lower_bound(uniq.begin(), uniq.end(), arr[1]) - uniq.begin();
  46.         auto v = seg.get(lb);
  47.         v.val = arr[1];
  48.         v.cnt += 1;
  49.         v.sum += v.val;
  50.         seg.set(lb, v);
  51.     }
  52.     for (int i = 2; i <= n; ++i) {
  53.         int lb = lower_bound(uniq.begin(), uniq.end(), arr[i]) - uniq.begin();
  54.         auto v1 = seg.prod(0, lb);
  55.         auto v2 = seg.prod(lb, tlen);
  56.         mint a = (i - 1), b = 1;
  57.         a /= i, b /= i;
  58.         mint c = 2 * a * b;
  59.  
  60.         mint comb = v1.cnt;
  61.         comb *= arr[i];
  62.         comb += v2.sum;
  63.         comb /= i;
  64.  
  65.         mint this_expect = a * a * prev_expect + c * comb + b * b * arr[i];
  66.         cout << this_expect.val() << endl;
  67.         prev_expect = this_expect;
  68.  
  69.         auto v3 = seg.get(lb);
  70.         v3.val = arr[i];
  71.         v3.cnt += 1;
  72.         v3.sum += v3.val;
  73.         seg.set(lb, v3);
  74.     }
  75.     return 0;
  76. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement