# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
930551 |
2024-02-20T06:24:55 Z |
Der_Vlapos |
Wall (IOI14_wall) |
C++17 |
|
603 ms |
73560 KB |
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pii pair<int, int>
#define ll long long
const int BIG = 2e9 + 500;
struct segTree
{
struct Node
{
int mx = 0, mn = BIG, last = 0;
};
vector<Node> tree;
int sz;
void init(int n)
{
sz = 1;
while (sz < n)
sz *= 2;
tree.resize(2 * sz);
}
// 0 - min=
// 1 - max=
int C1, C2, C3;
void upd(int v, pii op)
{
if (tree[v].last == op.f)
{
if (op.f == 1)
tree[v].mx = max(tree[v].mx, op.s);
else
tree[v].mn = min(tree[v].mn, op.s);
}
else
{
if (op.f == 1)
{
C1 = tree[v].mx;
C2 = tree[v].mn;
C3 = op.s;
tree[v].mx = max(min(C1, C2), C3);
}
else
{
C1 = tree[v].mn;
C2 = tree[v].mx;
C3 = op.s;
tree[v].mn = min(max(C1, C2), C3);
}
tree[v].last = op.f;
}
}
void push(int v)
{
if (tree[v].last == 0)
{
if (tree[v].mx != 0)
{
upd(v * 2 + 1, {1, tree[v].mx});
upd(v * 2 + 2, {1, tree[v].mx});
}
if (tree[v].mn != BIG)
{
upd(v * 2 + 1, {0, tree[v].mn});
upd(v * 2 + 2, {0, tree[v].mn});
}
}
else
{
if (tree[v].mn != BIG)
{
upd(v * 2 + 1, {0, tree[v].mn});
upd(v * 2 + 2, {0, tree[v].mn});
}
if (tree[v].mx != 0)
{
upd(v * 2 + 1, {1, tree[v].mx});
upd(v * 2 + 2, {1, tree[v].mx});
}
}
tree[v].mx = 0;
tree[v].mn = BIG;
}
void addOp(int l, int r, pii &op, int v, int lv, int rv)
{
if (l <= lv and rv <= r)
{
upd(v, op);
return;
}
if (rv <= l or r <= lv)
return;
int m = (lv + rv) >> 1;
push(v);
addOp(l, r, op, v * 2 + 1, lv, m);
addOp(l, r, op, v * 2 + 2, m, rv);
}
void addOp(int l, int r, pii op)
{
addOp(l, r, op, 0, 0, sz);
}
void outArray(vector<int> &a, int v, int lv, int rv)
{
if (rv - lv == 1)
{
if (lv < a.size())
{
// while (tree[v].ops.size())
// {
// pii op = tree[v].ops.front();
// tree[v].ops.pop_front();
// a[lv] = op.f ? max(a[lv], op.s) : min(a[lv], op.s);
// }
if (tree[v].last == 0)
{
// cout << lv << " " << tree[v].mx << " | " << tree[v].mn << "!\n";
a[lv] = max(a[lv], tree[v].mx);
a[lv] = min(a[lv], tree[v].mn);
}
else
{
// cout << lv << " | " << v << " " << tree[v].mn << " " << tree[v].mx << "!\n";
a[lv] = min(a[lv], tree[v].mn);
a[lv] = max(a[lv], tree[v].mx);
}
}
return;
}
int m = (lv + rv) >> 1;
push(v);
outArray(a, v * 2 + 1, lv, m);
outArray(a, v * 2 + 2, m, rv);
}
void outArray(vector<int> &a)
{
outArray(a, 0, 0, sz);
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
vector<int> a;
for (int i = 0; i < n; ++i)
a.push_back(finalHeight[i]);
segTree tree;
tree.init(n);
for (int i = 0; i < k; ++i)
{
op[i]--;
tree.addOp(left[i], right[i] + 1, {1 - op[i], height[i]});
}
tree.outArray(a);
for (int i = 0; i < n; ++i)
finalHeight[i] = a[i];
return;
}
// int main()
// {
// int n;
// int k;
// int i, j;
// int status = 0;
// status = scanf("%d%d", &n, &k);
// assert(status == 2);
// int *op = (int *)calloc(sizeof(int), k);
// int *left = (int *)calloc(sizeof(int), k);
// int *right = (int *)calloc(sizeof(int), k);
// int *height = (int *)calloc(sizeof(int), k);
// int *finalHeight = (int *)calloc(sizeof(int), n);
// for (i = 0; i < k; i++)
// {
// status = scanf("%d%d%d%d", &op[i], &left[i], &right[i], &height[i]);
// assert(status == 4);
// }
// buildWall(n, k, op, left, right, height, finalHeight);
// for (j = 0; j < n; j++)
// printf("%d\n", finalHeight[j]);
// return 0;
// }
Compilation message
wall.cpp: In member function 'void segTree::outArray(std::vector<int>&, int, int, int)':
wall.cpp:124:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | if (lv < a.size())
| ~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
5 ms |
860 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
4 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
105 ms |
8312 KB |
Output is correct |
3 |
Correct |
116 ms |
4700 KB |
Output is correct |
4 |
Correct |
341 ms |
12080 KB |
Output is correct |
5 |
Correct |
192 ms |
12044 KB |
Output is correct |
6 |
Correct |
183 ms |
12020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
6 ms |
860 KB |
Output is correct |
5 |
Correct |
4 ms |
856 KB |
Output is correct |
6 |
Correct |
4 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
107 ms |
8100 KB |
Output is correct |
9 |
Correct |
119 ms |
4708 KB |
Output is correct |
10 |
Correct |
339 ms |
12028 KB |
Output is correct |
11 |
Correct |
215 ms |
12124 KB |
Output is correct |
12 |
Correct |
225 ms |
12180 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
103 ms |
8108 KB |
Output is correct |
15 |
Correct |
30 ms |
1884 KB |
Output is correct |
16 |
Correct |
515 ms |
12196 KB |
Output is correct |
17 |
Correct |
208 ms |
12200 KB |
Output is correct |
18 |
Correct |
252 ms |
12120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
6 ms |
860 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
124 ms |
8176 KB |
Output is correct |
9 |
Correct |
114 ms |
4664 KB |
Output is correct |
10 |
Correct |
330 ms |
12120 KB |
Output is correct |
11 |
Correct |
190 ms |
12204 KB |
Output is correct |
12 |
Correct |
201 ms |
12224 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
105 ms |
8080 KB |
Output is correct |
15 |
Correct |
28 ms |
1884 KB |
Output is correct |
16 |
Correct |
524 ms |
12132 KB |
Output is correct |
17 |
Correct |
201 ms |
12128 KB |
Output is correct |
18 |
Correct |
197 ms |
12232 KB |
Output is correct |
19 |
Correct |
603 ms |
73136 KB |
Output is correct |
20 |
Correct |
490 ms |
73196 KB |
Output is correct |
21 |
Correct |
514 ms |
73260 KB |
Output is correct |
22 |
Correct |
498 ms |
73172 KB |
Output is correct |
23 |
Correct |
483 ms |
73176 KB |
Output is correct |
24 |
Correct |
489 ms |
73192 KB |
Output is correct |
25 |
Correct |
478 ms |
73560 KB |
Output is correct |
26 |
Correct |
479 ms |
73132 KB |
Output is correct |
27 |
Correct |
490 ms |
73140 KB |
Output is correct |
28 |
Correct |
476 ms |
73168 KB |
Output is correct |
29 |
Correct |
473 ms |
73492 KB |
Output is correct |
30 |
Correct |
493 ms |
73392 KB |
Output is correct |