Salvens

H

Aug 3rd, 2023
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <array>
  5. #include <set>
  6.  
  7. using namespace std;
  8.  
  9. #define int long long
  10.  
  11. const long long INF = 1e18 + 7;
  12. const int MAXN = 2e6 + 100;
  13. const int N = 1e5 + 10;
  14. const int MOD = 1e9 + 7;
  15.  
  16. array<pair<int, int>, 4 * MAXN> upd;
  17.  
  18. void push(int x, int lx, int rx) {
  19.     if (lx + 1 != rx) {
  20.         upd[2 * x + 1].first = max(upd[2 * x + 1].first, upd[x].first);
  21.         upd[2 * x + 1].first = min(upd[2 * x + 1].first, upd[x].second);
  22.         upd[2 * x + 1].second = max(upd[2 * x + 1].second, upd[x].first);
  23.         upd[2 * x + 1].second = min(upd[2 * x + 1].second, upd[x].second);
  24.  
  25.         upd[2 * x + 2].first = max(upd[2 * x + 2].first, upd[x].first);
  26.         upd[2 * x + 2].first = min(upd[2 * x + 2].first, upd[x].second);
  27.         upd[2 * x + 2].second = max(upd[2 * x + 2].second, upd[x].first);
  28.         upd[2 * x + 2].second = min(upd[2 * x + 2].second, upd[x].second);
  29.         upd[x] = {0, INF};
  30.     }
  31. }
  32.  
  33. void update(int x, int lx, int rx, int l, int r, int d, int type) {
  34.     push(x, lx, rx);
  35.     if (lx >= r || rx <= l) {
  36.         return;
  37.     }
  38.     if (lx >= l && rx <= r) {
  39.         if (type == 1) {
  40.             upd[x].first = max(upd[x].first, d);
  41.             upd[x].second = max(upd[x].second, d);
  42.         } else {
  43.             upd[x].first = min(upd[x].first, d);
  44.             upd[x].second = min(upd[x].second, d);
  45.         }
  46.         push(x, lx, rx);
  47.         return;
  48.     }
  49.     int mid = (rx + lx) / 2;
  50.     update(2 * x + 1, lx, mid, l, r, d, type);
  51.     update(2 * x + 2, mid, rx, l, r, d, type);
  52. }
  53.  
  54. int get(int x, int lx, int rx, int i) {
  55.     push(x, lx, rx);
  56.     if (lx + 1 == rx) {
  57.         return upd[x].first;
  58.     }
  59.     int mid = (lx + rx) / 2;
  60.     if (i < mid) {
  61.         return get(2 * x + 1, lx, mid, i);
  62.     } else {
  63.         return  get(2 * x + 2, mid, rx, i);
  64.     }
  65. }
  66.  
  67. signed main() {
  68.     ios_base::sync_with_stdio(false);
  69.     cin.tie(nullptr);
  70.     cout.tie(nullptr);
  71.     int n, m;
  72.     cin >> n >> m;
  73.     upd.fill({0, INF});
  74.     for (int i = 0; i < m; ++i) {
  75.         int type, l, r, d;
  76.         cin >> type >> l >> r >> d;
  77.         ++r;
  78.         update(0, 0, n, l, r, d, type);
  79.     }
  80.     for (int i = 0; i < n; ++i) {
  81.         cout << get(0, 0, n, i) << '\n';
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment