# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
674170 | kirakaminski968 | Wall (IOI14_wall) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <functional>
#include <numeric>
#include <utility>
#include <cassert>
using namespace std;
using pii = pair<int, int>;
#define MP make_pair
#define FF first
#define SS second
const int inf = 2000000011;
const pii def = MP(-inf, inf);
int N, Q;
pii T[8000000];
void init(int t = 1, int tl = 0, int tr = N - 1) {
if (tl == 0 && tr == N - 1)
T[t] = MP(0, 0);
else
T[t] = def;
if (tl == tr) return;
int tm = (tl + tr) >> 1;
init(t << 1, tl, tm);
init(t << 1 | 1, tm + 1, tr);
}
pii push(pii a, pii b) {
if (a.SS < b.FF)
return MP(a.SS, a.SS);
if (b.SS < a.FF)
return MP(a.FF, a.FF);
return MP(max(a.FF, b.FF), min(a.SS, b.SS));
}
void pushdown(int t) {
if (T[t] != def) {
T[t << 1] = push(T[t], T[t << 1]);
T[t << 1 | 1] = push(T[t], T[t << 1 | 1]);
T[t] = def;
}
}
void update(int l, int r, pii v, int t = 1, int tl = 0, int tr = N - 1) {
if (r < tl || tr < l)
return;
if (l <= tl && tr <= r) {
T[t] = push(v, T[t]);
return;
}
if (tl != tr)
pushdown(t);
int tm = (tl + tr) >> 1;
update(l, r, v, t << 1, tl, tm);
update(l, r, v, t << 1 | 1, tm + 1, tr);
}
void pushall(int* ans, int t = 1, int tl = 0, int tr = N - 1) {
if (tl == tr) {
ans[tl] = T[t].FF;
return;
}
else
pushdown(t);
int tm = (tl + tr) >> 1;
pushall(ans, t << 1, tl, tm);
pushall(ans, t << 1 | 1, tm + 1, tr);
}
void buildWall(int n, int k, int* op, int* lb, int* rb, int* h, int* ans) {
N = n, Q = k;
init();
for (int q = 0; q < Q; q++) {
pii v = def;
if (op[q] == 1)
v.FF = h[q];
else if (op[q] == 2)
v.SS = h[q];
update(lb[q], rb[q], v);
}
pushall(ans);
}
int n, q, op[500005], lb[500005], rb[500005], h[500005], ans[500005];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> q;
for (int i = 0; i < q; i++)
cin >> op[i] >> lb[i] >> rb[i] >> h[i];
buildWall(n, q, op, lb, rb, h, ans);
for (int i = 0; i < n; i++)
cout << ans[i] << ' ';
cout << endl;
}