# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1007008 |
2024-06-24T10:53:06 Z |
Ausp3x |
Wall (IOI14_wall) |
C++17 |
|
78 ms |
8020 KB |
// 人外有人,天外有天
// author: Ausp3x
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
typedef long long lng;
typedef unsigned int uint;
typedef unsigned long long ulng;
using namespace std;
using namespace __gnu_pbds;
int const INF32 = 0x3f3f3f3f;
lng const INF64 = 0x3f3f3f3f3f3f3f3f;
int nextPowOf2(int n) {
n--;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n++;
return n;
}
int n2;
vector<pair<int, int>> segt;
void update(int op, int l, int r, int turn, int h) {
l += n2;
r += n2;
if (op == 1)
while (l <= r) {
if (l & 1) {
if (segt[l].first == -1 || segt[l].second < h)
segt[l] = {turn, h};
l++;
}
if (!(r & 1)) {
if (segt[r].first == -1 || segt[r].second < h)
segt[r] = {turn, h};
r--;
}
l >>= 1;
r >>= 1;
}
else if (op == 2) {
while (l <= r) {
if (l & 1) {
if (segt[l].first == -1 || segt[l].second > h)
segt[l] = {turn, h};
l++;
}
if (!(r & 1)) {
if (segt[r].first == -1 || segt[r].second > h)
segt[r] = {turn, h};
r--;
}
l >>= 1;
r >>= 1;
}
}
return;
}
lng query(int op[], int i) {
i += n2;
vector<pair<int, int>> pending_updates;
while (i > 0) {
if (segt[i].first != -1)
pending_updates.push_back(segt[i]);
i >>= 1;
}
sort(pending_updates.begin(), pending_updates.end());
int res = 0;
for (auto [turn, h] : pending_updates)
if (op[turn] == 1 && res < h)
res = h;
else if (op[turn] == 2 && res > h)
res = h;
return res;
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
n2 = nextPowOf2(n);
segt.clear();
segt.resize(2 * n2, {-1, 0});
for (int i = 0; i < k; i++) {
update(op[i], left[i], right[i], i, height[i]);
}
for (int i = 0; i < n; i++)
finalHeight[i] = query(op, i);
// for (int i = 0; i < n; i++)
// cout << finalHeight[i] << ' ';
// cout << endl;
return;
}
/*
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
int op[k], left[k], right[k], height[k], finalHeight[n];
for (int i = 0; i < k; i++)
cin >> op[i] >> left[i] >> right[i] >> height[i];
buildWall(n, k, op, left, right, height, finalHeight);
}
return 0;
}
//*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
78 ms |
8020 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |