Advertisement
tiom4eg

openol D 100

Jan 16th, 2023
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define ld long double
  9. #define ull unsigned long long
  10. #define pii pair <int, int>
  11. #define vi vector <int>
  12. #define mi vector <vector <int>>
  13. // Quick functions
  14. #define endl "\n"
  15. #define F first
  16. #define S second
  17. #define all(a) a.begin(), a.end()
  18. #define sz(a) (int)(a.size())
  19. #define pb push_back
  20. #define mp make_pair
  21. // Quick fors
  22. #define FOR(i, a, b) for (int i = a; i < b; ++i)
  23. #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
  24. #define RFOR(i, a, b) for (int i = a; i >= b; --i)
  25. #define EACH(e, a) for (auto& e : a)
  26. // Pragmas
  27. #ifndef TIOM4EG
  28. #pragma GCC optimize("O3,unroll-loops") // let the chaos begin!
  29. #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
  30. #pragma GCC comment(linker, "/stack:200000000")
  31. #endif
  32. // PBDS
  33. #include <ext/pb_ds/assoc_container.hpp>
  34. #include <ext/pb_ds/tree_policy.hpp>
  35. #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  36. #define ook order_of_key
  37. #define fbo find_by_order
  38. using namespace __gnu_pbds;
  39. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  40. using namespace std;
  41. mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
  42. //#define int long long
  43. const int INF = 1e9 + 7, INFLL = 1e13 + 7, MD = 998244353, R = 1 << 18, MOD = 1e9 + 7, MAX = 300009, LG = 30, B = 31, S = 10008;
  44.  
  45. int mnpt[2 * R], mxpt[2 * R], tott[2 * R], totp[2 * R], prp[2 * R];
  46.  
  47. void merge(int v) { mnpt[v] = min(mnpt[2 * v], mnpt[2 * v + 1]), mxpt[v] = max(mxpt[2 * v], mxpt[2 * v + 1]), tott[v] = tott[2 * v] + tott[2 * v + 1]; }
  48. void push(int v, int l) {
  49.     if (v >= R) return;
  50.     if (prp[v] != -1) mnpt[2 * v] = mxpt[2 * v] = mnpt[2 * v + 1] = mxpt[2 * v + 1] = prp[2 * v] = prp[2 * v + 1] = prp[v];
  51.     if (totp[v]) tott[2 * v] += totp[v] * (l / 2), tott[2 * v + 1] += totp[v] * (l / 2), totp[2 * v] += totp[v], totp[2 * v + 1] += totp[v];
  52.     prp[v] = -1, totp[v] = 0;
  53. }
  54. void build() { FOR(i, 1, 2 * R) mnpt[i] = mxpt[i] = INF, prp[i] = -1; }
  55. void add(int ql, int qr, int x, int v = 1, int nl = 0, int nr = R) {
  56.     push(v, nr - nl);
  57.     if (nr <= ql || qr <= nl || mxpt[v] < x) return;
  58.     if (ql <= nl && nr <= qr && mnpt[v] > x) {
  59.         mnpt[v] = mxpt[v] = prp[v] = x;
  60.         push(v, nr - nl);
  61.         return;
  62.     }
  63.     int nm = (nl + nr) / 2;
  64.     add(ql, qr, x, 2 * v, nl, nm), add(ql, qr, x, 2 * v + 1, nm, nr);
  65.     merge(v);
  66. }
  67. void del(int ql, int qr, int x, int v = 1, int nl = 0, int nr = R) {
  68.     push(v, nr - nl);
  69.     if (nr <= ql || qr <= nl || mnpt[v] == INF) return;
  70.     if (ql <= nl && nr <= qr && mnpt[v] == mxpt[v]) {
  71.         totp[v] += x - mnpt[v], tott[v] += (nr - nl) * (x - mnpt[v]);
  72.         mnpt[v] = mxpt[v] = prp[v] = INF;
  73.         push(v, nr - nl);
  74.         return;
  75.     }
  76.     int nm = (nl + nr) / 2;
  77.     del(ql, qr, x, 2 * v, nl, nm), del(ql, qr, x, 2 * v + 1, nm, nr);
  78.     merge(v);
  79. }
  80. int get(int ql, int qr, int v = 1, int nl = 0, int nr = R) {
  81.     push(v, nr - nl);
  82.     if (nr <= ql || qr <= nl) return 0;
  83.     if (ql <= nl && nr <= qr) return tott[v];
  84.     int nm = (nl + nr) / 2;
  85.     return get(ql, qr, 2 * v, nl, nm) + get(ql, qr, 2 * v + 1, nm, nr);
  86. }
  87.  
  88. signed main() {
  89.     fastIO;
  90.     int n, q; cin >> n >> q;
  91.     build();
  92.     FOR(i, 0, q) {
  93.         char op; int l, r; cin >> op >> l >> r, --l;
  94.         if (op == '+') add(l, r, i);
  95.         else del(l, r, i);
  96.     }
  97.     del(0, n, q);
  98.     FOR(i, 0, n) cout << q - get(i, i + 1) << ' ';
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement