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 "wall.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Segtree {
int n;
vector<pair<int, P>> dat;
vector<int> s;
Segtree(int n_) {
n = 1;
while (n < n_) {
n <<= 1;
}
dat.resize(2 * n, make_pair(-1, P(-1, -1)));
s.resize(2 * n, -1);
}
void upd(int a, int b, P x, int t, int k, int l, int r) {
if (b <= l || r <= a) {
return;
}
if (a <= l && r <= b) {
if (x.second == 1) {
if (s[k] < x.first) {
dat[k] = make_pair(t, x);
s[k] = x.first;
}
} else {
if (s[k] == -1 || s[k] > x.first) {
dat[k] = make_pair(t, x);
s[k] = x.first;
}
}
return;
}
upd(a, b, x, t, k << 1, l, (l + r) >> 1);
upd(a, b, x, t, k << 1 | 1, (l + r) >> 1, r);
}
void upd(int a, int b, P x, int t) { upd(a, b, x, t, 1, 0, n); }
vector<pair<int, P>> get(int k) {
k += n;
vector<pair<int, P>> res;
if (dat[k].first != -1) {
res.push_back(dat[k]);
}
k >>= 1;
while (k > 0) {
if (dat[k].first != -1) {
res.push_back(dat[k]);
}
k >>= 1;
}
sort(res.begin(), res.end());
return res;
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[],
int finalHeight[]) {
if (k <= 5000 && n <= 10000) {
for (int i = 0; i < n; i++) {
finalHeight[i] = 0;
}
for (int i = 0; i < k; i++) {
for (int j = left[i]; j <= right[i]; j++) {
if (op[i] == 1) {
finalHeight[j] = max(finalHeight[j], height[j]);
} else {
finalHeight[j] = min(finalHeight[j], height[j]);
}
}
}
} else {
Segtree seg(n);
for (int i = 0; i < k; i++) {
seg.upd(left[i], right[i] + 1, P(height[i], op[i]), i);
}
for (int i = 0; i < n; i++) {
int t = 0;
vector<pair<int, P>> v = seg.get(i);
for (auto &p : v) {
if (p.second.second == 1) {
t = max(t, p.second.first);
} else {
t = min(t, p.second.first);
}
}
finalHeight[i] = t;
}
}
}
# | 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... |