| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1295386 | kantaponz | Wall (IOI14_wall) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1e9
struct Node {
int mn, mx;
Node() {
mn = 0, mx = INF;
}
};
int N, K;
Node tree[8000005];
Node lazy[8000005];
bool hasLazy[8000005];
Node intersect(Node &a, Node &b) { // (prev_node, update_node)
Node ans = Node();
if (a.mx < b.mn) {
ans.mn = b.mn;
ans.mx = b.mn;
} else if (a.mn > b.mx) {
ans.mn = b.mx;
ans.mx = b.mx;
} else {
ans.mn = max(a.mn, b.mn);
ans.mx = min(a.mx, b.mx);
}
return ans;
}
void push(int idx, int l, int r) {
if (!hasLazy[idx]) return;
tree[idx] = intersect(tree[idx], lazy[idx]);
if (l != r) {
lazy[idx*2] = intersect(lazy[idx*2], lazy[idx]);
lazy[idx*2+1] = intersect(lazy[idx*2+1], lazy[idx]);
hasLazy[2*idx] = hasLazy[2*idx+1] = 1;
}
lazy[idx] = Node();
hasLazy[idx] = 0;
}
void updateLower(int idx, int l, int r, int ql, int qr, int val) {
if (r < ql || l > qr) return;
if (ql <= l && r <= qr) {
Node A = Node();
A.mn = val;
lazy[idx] = intersect(lazy[idx], A);
hasLazy[idx] = 1;
push(idx, l, r);
return;
}
if (l != r) {
push(idx, l, r);
int mid = (l + r) >> 1;
updateLower(2*idx, l, mid, ql, qr, val);
updateLower(2*idx+1, mid + 1, r, ql, qr, val);
}
}
void updateUpper(int idx, int l, int r, int ql, int qr, int val) {
if (r < ql || l > qr) return;
if (ql <= l && r <= qr) {
Node A = Node();
A.mx = val;
lazy[idx] = intersect(lazy[idx], A);
hasLazy[idx] = 1;
push(idx, l, r);
return;
}
if (l != r) {
push(idx, l, r);
int mid = (l + r) >> 1;
updateUpper(2*idx, l, mid, ql, qr, val);
updateUpper(2*idx+1, mid + 1, r, ql, qr, val);
}
}
int query(int idx, int l, int r, int k) {
push(idx, l, r);
if (l == r) {
return tree[idx].mn;
}
int mid = (l + r) >> 1;
if (k <= mid) {
return query(idx*2, l, mid, k);
} else {
return query(idx*2 + 1, mid + 1, r, k);
}
return 0;
}
void print_tree(int idx, int l, int r) {
cout << "[" << l << "," << r << "] : " << tree[idx].mn << " " << tree[idx].mx << endl;
if (l != r) {
int mid = (l + r) >> 1;
print_tree(2*idx, l, mid);
print_tree(2*idx+1, mid + 1, r);
}
}
void print_lazy(int idx, int l, int r) {
cout << "[" << l << "," << r << "] : " << lazy[idx].mn << " " << lazy[idx].mx << endl;
if (l != r) {
int mid = (l + r) >> 1;
print_lazy(2*idx, l, mid);
print_lazy(2*idx+1, mid + 1, r);
}
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
N = n, K = k;
for (int i = 0; i < k; i++) {
if (op[i] == 1) {
updateLower(1, 0, N - 1, left[i], right[i], height[i]);
} else {
updateUpper(1, 0, N - 1, left[i], right[i], height[i]);
}
}
/*
print_tree(1, 0, N - 1);
cout << "\n--------\n";
print_lazy(1, 0, N - 1);
cout << "\n--------\n";
*/
for (int i = 0; i < N; i++) {
finalHeight[i] = query(1, 0, N - 1, i);
}
}
int main()
{
int n;
int k;
int i, j;
int status = 0;
status = scanf("%d%d", &n, &k);
assert(status == 2);
int* op = (int*)calloc(sizeof(int), k);
int* left = (int*)calloc(sizeof(int), k);
int* right = (int*)calloc(sizeof(int), k);
int* height = (int*)calloc(sizeof(int), k);
int* finalHeight = (int*)calloc(sizeof(int), n);
for (i = 0; i < k; i++){
status = scanf("%d%d%d%d", &op[i], &left[i], &right[i], &height[i]);
assert(status == 4);
}
buildWall(n, k, op, left, right, height, finalHeight);
for (j = 0; j < n; j++)
printf("%d\n", finalHeight[j]);
return 0;
}
/*
10 6
1 1 8 4
2 4 9 1
2 3 6 5
1 0 5 3
1 2 2 5
2 6 7 0
*/
