# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
790390 |
2023-07-22T15:34:56 Z |
Elias |
Wall (IOI14_wall) |
C++17 |
|
569 ms |
130676 KB |
#include <bits/stdc++.h>
using namespace std;
#ifndef _DEBUG
#include "wall.h"
#endif
template <class T>
istream &operator>>(istream &in, vector<T> &a)
{
for (auto &x : a)
in >> x;
return in;
}
int minusMin(int a, int b)
{
if (a == -1)
return b;
if (b == -1)
return a;
return min(a, b);
}
int minusMax(int a, int b)
{
if (a == -1)
return b;
if (b == -1)
return a;
return max(a, b);
}
struct Node
{
int low = -1;
int high = -1;
bool first = 0;
void Apply(Node update)
{
if (this->low == -1 && this->high == -1)
{
*this = update;
return;
}
if (update.low == -1 && update.high == -1)
return;
low = minusMax(low, update.low);
high = minusMin(high, update.high);
if (low > high && high != -1)
{
low = high = ((low == update.low) ? update.low : update.high);
}
bool a = low == update.low && low != -1;
bool b = high == update.high && high != -1;
if (a && b)
first = update.low;
else if (a)
first = 0;
else if (b)
first = 1;
}
};
Node emp = {-1, -1, 0};
vector<Node> b;
void updateRange(int l, int r, int i, int ul, int ur, Node up)
{
if (l >= ur || r <= ul)
return;
if (l >= ul && r <= ur)
{
b[i].Apply(up);
return;
}
b[i * 2 + 1].Apply(b[i]);
b[i * 2 + 2].Apply(b[i]);
b[i] = emp;
int m = (l + r) / 2;
updateRange(l, m, i * 2 + 1, ul, ur, up);
updateRange(m, r, i * 2 + 2, ul, ur, up);
}
void extractValues(int l, int r, int i, int a[])
{
if (l + 1 == r)
{
a[l] = max(b[i].low, 0);
return;
}
b[i * 2 + 1].Apply(b[i]);
b[i * 2 + 2].Apply(b[i]);
b[i] = emp;
int m = (l + r) / 2;
extractValues(l, m, i * 2 + 1, a);
extractValues(m, r, i * 2 + 2, a);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
b = vector<Node>(n * 4, emp);
for (int i = 0; i < k; i++)
updateRange(0, n, 0, left[i], right[i] + 1, ((op[i] == 1) ? Node{height[i], -1, 0} : Node{-1, height[i], 1}));
extractValues(0, n, 0, finalHeight);
}
#ifdef _DEBUG
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<int> op, left, right, height;
op = left = right = height = vector<int>(k);
cin >> op >> left >> right >> height;
vector<int> finalHeight(n);
buildWall(n, k, op, left, right, height, finalHeight);
for (int &x : finalHeight)
cout << x << " ";
cout << "\n";
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
1016 KB |
Output is correct |
5 |
Correct |
4 ms |
980 KB |
Output is correct |
6 |
Correct |
6 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
296 KB |
Output is correct |
2 |
Correct |
105 ms |
13936 KB |
Output is correct |
3 |
Correct |
184 ms |
8248 KB |
Output is correct |
4 |
Correct |
551 ms |
22948 KB |
Output is correct |
5 |
Correct |
227 ms |
24008 KB |
Output is correct |
6 |
Correct |
220 ms |
22444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
440 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
9 ms |
988 KB |
Output is correct |
5 |
Correct |
6 ms |
948 KB |
Output is correct |
6 |
Correct |
6 ms |
984 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
126 ms |
13896 KB |
Output is correct |
9 |
Correct |
174 ms |
8252 KB |
Output is correct |
10 |
Correct |
532 ms |
22940 KB |
Output is correct |
11 |
Correct |
236 ms |
24000 KB |
Output is correct |
12 |
Correct |
221 ms |
22440 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
106 ms |
13820 KB |
Output is correct |
15 |
Correct |
32 ms |
2304 KB |
Output is correct |
16 |
Correct |
558 ms |
23204 KB |
Output is correct |
17 |
Correct |
257 ms |
22604 KB |
Output is correct |
18 |
Correct |
262 ms |
22624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
980 KB |
Output is correct |
5 |
Correct |
4 ms |
980 KB |
Output is correct |
6 |
Correct |
4 ms |
956 KB |
Output is correct |
7 |
Correct |
0 ms |
296 KB |
Output is correct |
8 |
Correct |
104 ms |
13888 KB |
Output is correct |
9 |
Correct |
173 ms |
8244 KB |
Output is correct |
10 |
Correct |
528 ms |
23072 KB |
Output is correct |
11 |
Correct |
223 ms |
24020 KB |
Output is correct |
12 |
Correct |
221 ms |
22484 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
111 ms |
13900 KB |
Output is correct |
15 |
Correct |
32 ms |
2304 KB |
Output is correct |
16 |
Correct |
562 ms |
23200 KB |
Output is correct |
17 |
Correct |
228 ms |
22664 KB |
Output is correct |
18 |
Correct |
241 ms |
22624 KB |
Output is correct |
19 |
Correct |
547 ms |
130504 KB |
Output is correct |
20 |
Correct |
552 ms |
128168 KB |
Output is correct |
21 |
Correct |
545 ms |
130580 KB |
Output is correct |
22 |
Correct |
548 ms |
128040 KB |
Output is correct |
23 |
Correct |
569 ms |
128100 KB |
Output is correct |
24 |
Correct |
544 ms |
128084 KB |
Output is correct |
25 |
Correct |
541 ms |
128144 KB |
Output is correct |
26 |
Correct |
546 ms |
130520 KB |
Output is correct |
27 |
Correct |
559 ms |
130676 KB |
Output is correct |
28 |
Correct |
549 ms |
127976 KB |
Output is correct |
29 |
Correct |
541 ms |
128116 KB |
Output is correct |
30 |
Correct |
565 ms |
128028 KB |
Output is correct |