Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <array>
- #include <set>
- using namespace std;
- #define int long long
- const long long INF = 1e18 + 7;
- const int MAXN = 2e6 + 100;
- const int N = 1e5 + 10;
- const int MOD = 1e9 + 7;
- array<pair<int, int>, 4 * MAXN> upd;
- void push(int x, int lx, int rx) {
- if (lx + 1 != rx) {
- upd[2 * x + 1].first = max(upd[2 * x + 1].first, upd[x].first);
- upd[2 * x + 1].first = min(upd[2 * x + 1].first, upd[x].second);
- upd[2 * x + 1].second = max(upd[2 * x + 1].second, upd[x].first);
- upd[2 * x + 1].second = min(upd[2 * x + 1].second, upd[x].second);
- upd[2 * x + 2].first = max(upd[2 * x + 2].first, upd[x].first);
- upd[2 * x + 2].first = min(upd[2 * x + 2].first, upd[x].second);
- upd[2 * x + 2].second = max(upd[2 * x + 2].second, upd[x].first);
- upd[2 * x + 2].second = min(upd[2 * x + 2].second, upd[x].second);
- upd[x] = {0, INF};
- }
- }
- void update(int x, int lx, int rx, int l, int r, int d, int type) {
- push(x, lx, rx);
- if (lx >= r || rx <= l) {
- return;
- }
- if (lx >= l && rx <= r) {
- if (type == 1) {
- upd[x].first = max(upd[x].first, d);
- upd[x].second = max(upd[x].second, d);
- } else {
- upd[x].first = min(upd[x].first, d);
- upd[x].second = min(upd[x].second, d);
- }
- push(x, lx, rx);
- return;
- }
- int mid = (rx + lx) / 2;
- update(2 * x + 1, lx, mid, l, r, d, type);
- update(2 * x + 2, mid, rx, l, r, d, type);
- }
- int get(int x, int lx, int rx, int i) {
- push(x, lx, rx);
- if (lx + 1 == rx) {
- return upd[x].first;
- }
- int mid = (lx + rx) / 2;
- if (i < mid) {
- return get(2 * x + 1, lx, mid, i);
- } else {
- return get(2 * x + 2, mid, rx, i);
- }
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n, m;
- cin >> n >> m;
- upd.fill({0, INF});
- for (int i = 0; i < m; ++i) {
- int type, l, r, d;
- cin >> type >> l >> r >> d;
- ++r;
- update(0, 0, n, l, r, d, type);
- }
- for (int i = 0; i < n; ++i) {
- cout << get(0, 0, n, i) << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment