# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
881196 |
2023-11-30T20:54:53 Z |
OAleksa |
Wall (IOI14_wall) |
C++14 |
|
0 ms |
0 KB |
#include<bits/stdc++.h>
#include "wall.h"
using namespace std;
#define int long long
#define f first
#define s second
const int maxn = 2e6 + 69;
const int inf = 1e10;
int mn[4 * maxn], mx[4 * maxn], lst[4 * maxn];
void push(int v) {
int ch1 = v * 2, ch2 = v * 2 + 1;
int a = mx[v], b = mn[v];
int c = mx[ch1], d = mn[ch1];
int e = mx[ch2], f = mn[ch2];
if (a == 0 && b == inf)
return;
if (a >= d)
mx[ch1] = mn[ch1] = a;
else if (b <= c)
mn[ch1] = mx[ch1] = b;
else {
mx[ch1] = max(mx[ch1], a);
mn[ch1] = min(mn[ch1], b);
}
if (a >= f)
mx[ch2] = mn[ch2] = a;
else if (b <= e)
mn[ch2] = mx[ch2] = b;
else {
mx[ch2] = max(mx[ch2], a);
mn[ch2] = min(mn[ch2], b);
}
mn[v] = inf;
mx[v] = 0;
lst[ch1] = lst[ch2] = lst[v];
}
void updmax(int v, int tl, int tr, int l, int r, int x) {
if (tl > r || tr < l)
return;
else if (tl >= l && tr <= r) {
if (x > mn[v])
mn[v] = mx[v] = x;
else {
mx[v] = max(mx[v], x);
mn[v] = min(mn[v], inf);
}
lst[v] = 1;
}
else {
push(v);
int mid = (tl + tr) / 2;
updmax(v * 2, tl, mid, l, r, x);
updmax(v * 2 + 1, mid + 1, tr, l, r, x);
}
}
void updmin(int v, int tl, int tr, int l, int r, int x) {
if (tl > r || tr < l)
return;
else if (tl >= l && tr <= r) {
if (x < mx[v])
mx[v] = mn[v] = x;
else {
mx[v] = max(mx[v], 0ll);
mn[v] = min(mn[v], x);
}
lst[v] = 0;
}
else {
push(v);
int mid = (tl + tr) / 2;
updmin(v * 2, tl, mid, l, r, x);
updmin(v * 2 + 1, mid + 1, tr, l, r, x);
}
}
int get(int v, int tl, int tr, int p) {
if (tl == tr) {
if (lst[v])
return mx[v];
return mn[v];
}
else {
int mid = (tl + tr) / 2;
push(v);
if (p <= mid)
return get(v * 2, tl, mid, p);
else
return get(v * 2 + 1, mid + 1, tr, p);
}
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
for (int i = 0;i < k;i++) {
left[i]++;
right[i]++;
if (op[i] == 1)
updmax(1, 1, n, left[i], right[i], height[i]);
else
updmin(1, 1, n, left[i], right[i], height[i]);
}
for (int i = 0;i < n;i++)
finalHeight[i] = get(1, 1, n, i + 1);
for (int i = 0;i < n;i++)
cout << finalHeight[i] << endl;
return;
}
// signed main() {
// ios_base::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
// int tt = 1;
// //cin >> tt;
// while (tt--) {
// int n, q;
// cin >> n >> q;
// int a[q], b[q], c[q], d[q], e[q];
// for (int i = 0;i < q;i++)
// cin >> a[i] >> b[i] >> c[i] >> d[i];
// buildWall(n, q, a, b, c, d, e);
// }
// return 0;
// }
Compilation message
/usr/bin/ld: /tmp/cc5Lzka8.o: in function `main':
grader.cpp:(.text.startup+0x133): undefined reference to `buildWall(int, int, int*, int*, int*, int*, int*)'
collect2: error: ld returned 1 exit status