#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void sum(pair<ll, ll> &a, pair<ll, ll> b) {
if (a.second <= b.first) {
a.first = b.first;
a.second = b.first;
return;
}
if (b.second <= a.first) {
a.first = b.second;
a.second = b.second;
return;
}
a.first = max(a.first, b.first);
a.second = min(a.second, b.second);
return;
}
void upd(int v, vector<pair<ll, ll>> &tr) {
sum(tr[v*2], tr[v]);
sum(tr[v*2+1], tr[v]);
tr[v] = {0, 1e9};
}
void add(int v, int p, int k, vector<pair<ll, ll>> &tr, int a, int b, pair<ll, ll> x) {
if (a <= p && k <= b) {
sum(tr[v], x);
return;
}
if (a > k || b < p) {
return;
}
upd(v, tr);
add(v*2, p, (p+k)/2, tr, a, b, x);
add(v*2+1, (p+k)/2+1, k, tr, a, b, x);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
vector<pair<ll, ll>> tr (1<<22, {0, 1e9});
for (int i = 1<<21; i < 1<<22; i++) {
tr[i] = {0, 0};
}
for (int i = 0; i < k; i++) {
pair<ll, ll> x;
if (op[i] == 1) {
x = {height[i], 1e9};
}
else {
x = {0, height[i]};
}
add(1, 0, (1<<21)-1, tr, left[i], right[i], x);
}
for (int i = 1; i < 1<<21; i++) {
upd(i, tr);
}
for (int i = 0; i < n; i++) {
finalHeight[i] = tr[i+(1<<21)].first;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |