# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
159306 |
2019-10-22T09:05:47 Z |
TAISA_ |
Wall (IOI14_wall) |
C++14 |
|
171 ms |
13944 KB |
#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 |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
4 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
171 ms |
13944 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |