#include "towers.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
namespace
{
int N;
vector<int> H, p, l, r, vis;
map<int, int> mp;
}
void init(int _N, vector<int> _H)
{
N = _N;
H = _H;
H.emplace_back(2e9);
p = vector<int>(N + 1, 0);
vector<int> l = p, r = p, vis = p;
vector<int> mono = {N};
for (int i = 0; i <= N; i++)
{
while (H[mono.back()] < H[i])
r[mono.back()] = i, mono.pop_back();
l[i] = mono.back();
mono.push_back(i);
}
for (int i = 0; i < N; i++)
if (H[l[i]] < H[r[i]])
p[i] = l[i];
else
p[i] = r[i];
p[N] = N + 1;
vector<int> v;
for (int i = 0; i < N; i++)
vis[p[i]] = 1;
for (int i = 0; i < N; i++)
if (!vis[i])
v.emplace_back(i);
sort(v.begin(), v.end(), [&](int i, int j)
{ return H[i] < H[j]; });
for (int i = 0; i <= N; i++)
vis[i] = 0;
vector<int> inc;
for (auto i : v)
{
int c = i, D = 0;
while (c != N + 1)
{
D = H[c] - H[i];
if(vis[c])
break;
vis[c] = 1;
c = p[c];
}
inc.emplace_back(D);
}
sort(inc.begin(), inc.end(), greater<>());
int acc = 0;
for (auto i : inc)
{
acc++;
mp[i] = acc;
}
}
int max_towers(int L, int R, int D)
{
return mp.lower_bound(D)->second;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
330 ms |
2020 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
448 ms |
4764 KB |
1st lines differ - on the 1st token, expected: '11903', found: '33010' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
1388 KB |
Output is correct |
2 |
Correct |
564 ms |
4760 KB |
Output is correct |
3 |
Correct |
594 ms |
4756 KB |
Output is correct |
4 |
Correct |
638 ms |
5784 KB |
Output is correct |
5 |
Correct |
594 ms |
5668 KB |
Output is correct |
6 |
Correct |
651 ms |
5784 KB |
Output is correct |
7 |
Correct |
617 ms |
5672 KB |
Output is correct |
8 |
Correct |
534 ms |
2968 KB |
Output is correct |
9 |
Correct |
620 ms |
3868 KB |
Output is correct |
10 |
Correct |
543 ms |
3016 KB |
Output is correct |
11 |
Correct |
608 ms |
3784 KB |
Output is correct |
12 |
Correct |
20 ms |
4780 KB |
Output is correct |
13 |
Correct |
24 ms |
5668 KB |
Output is correct |
14 |
Correct |
23 ms |
5672 KB |
Output is correct |
15 |
Correct |
17 ms |
3872 KB |
Output is correct |
16 |
Correct |
17 ms |
2964 KB |
Output is correct |
17 |
Correct |
22 ms |
4648 KB |
Output is correct |
18 |
Correct |
22 ms |
4748 KB |
Output is correct |
19 |
Correct |
21 ms |
4744 KB |
Output is correct |
20 |
Correct |
23 ms |
5780 KB |
Output is correct |
21 |
Correct |
23 ms |
5776 KB |
Output is correct |
22 |
Correct |
23 ms |
5668 KB |
Output is correct |
23 |
Correct |
25 ms |
5784 KB |
Output is correct |
24 |
Correct |
10 ms |
2976 KB |
Output is correct |
25 |
Correct |
10 ms |
3856 KB |
Output is correct |
26 |
Correct |
12 ms |
2972 KB |
Output is correct |
27 |
Correct |
11 ms |
3924 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
0 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
0 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
0 ms |
336 KB |
Output is correct |
42 |
Correct |
0 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
330 ms |
2020 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |