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 <bits/stdc++.h>
#define ALL(arr) begin(arr), end(arr)
using namespace std;
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
// x, ind, end, adding, height
vector<tuple<int, int, bool, int>> addactions;
vector<tuple<int, int, bool, int>> remactions;
for (int i = 0; i < k; i++) {
if (op[i] == 1) {
addactions.push_back({left[i], i, false, height[i]});
addactions.push_back({right[i]+1, i, true, height[i]});
} else {
remactions.push_back({left[i], i, false, height[i]});
remactions.push_back({right[i]+1, i, true, height[i]});
}
}
sort(ALL(addactions));
sort(ALL(remactions));
int px = 0;
multiset<int, greater<int>> prevHeights;
prevHeights.insert(0);
for (auto [x, ind, end, goalheight] : addactions) {
fill(finalHeight + px, finalHeight + x, *prevHeights.begin());
px = x;
if (!end) {
prevHeights.insert(goalheight);
} else {
auto it = prevHeights.find(goalheight);
prevHeights.erase(it);
}
}
fill(finalHeight + px, finalHeight + n, 0);
px = 0;
multiset<int> prevHeights2;
prevHeights2.insert(1e8);
int maxH = 0;
for (auto [x, ind, end, goalheight] : remactions) {
for (int i = px; i < x; i++) {
maxH = finalHeight[i];
finalHeight[i] = min(*prevHeights2.begin(), maxH);
}
px = x;
if (!end) {
prevHeights2.insert(goalheight);
} else {
auto it = prevHeights2.find(goalheight);
prevHeights2.erase(it);
}
}
return;
}
# | 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... |