#include "towers.h"
#include <vector>
#include <algorithm>
#include <numeric>
#include <iostream>
namespace ruhan {
using namespace std;
int N;
vector<int> H;
vector<int> max_rmq[20];
vector<int> min_rmq[20];
int good_pos = -1;
vector<int> lg;
int my_max (int x, int y) {
return H[x] > H[y] ? x : y;
}
int my_min (int x, int y) {
return H[x] < H[y] ? x : y;
}
template<class F>
void rmq_init (vector<int> *rmq, F func) {
rmq[0].resize(N);
iota(rmq[0].begin(), rmq[0].end(), 0);
for (int k = 0; k < 19; k++) {
rmq[k+1].resize(N);
for (int i = 0; i < N; i++) {
if (i + (1 << k) < N) rmq[k+1][i] = func(rmq[k][i], rmq[k][i+(1<<k)]);
else rmq[k+1][i] = rmq[k][i];
}
}
}
template<class F>
int rmq_get (vector<int> *rmq, F func, int l, int r) {
int k = lg[r - l + 1];
return func(rmq[k][l], rmq[k][r - (1 << k) + 1]);
}
void init (int N_, vector<int> H_) {
N = N_; H = H_;
for (int i = 0; i < N; i++) {
if ((i == 0 || H[i-1] < H[i]) && (i == N - 1 || H[i+1] > H[i])) {
if (good_pos == -1) good_pos = i;
else good_pos = -2;
}
}
rmq_init(max_rmq, my_max);
rmq_init(min_rmq, my_min);
lg.resize(N + 1);
lg[1] = 0;
for (int x = 2; x <= N; x++) {
lg[x] = lg[x/2] + 1;
}
//cerr << "init done\n";
}
int calc (int L, int R, int D, int mx) {
if (good_pos >= 0) {
if (good_pos <= L && good_pos >= R) return 1;
int x = rmq_get(min_rmq, my_min, L, good_pos - 1);
int y = rmq_get(min_rmq, my_min, good_pos + 1, R);
if (H[x] + D <= H[good_pos] && H[y] + D <= H[good_pos]) return 2;
else return 1;
}
if (L > R) return 0;
if (L == R) return H[L] <= mx;
//cerr << L << " " << R << " " << D << " " << mx << ", ";
int xi = rmq_get(min_rmq, my_min, L, R);
int yi = rmq_get(max_rmq, my_max, L, R);
//cerr << "xi = " << xi << ", yi = " << yi << "\n";
if (H[xi] > mx) return 0;
return max(1, calc(L, yi - 1, D, H[yi] - D) + calc(yi + 1, R, D, H[yi] - D));
}
};
void init(int N, std::vector<int> H) {
ruhan::init(N, H);
}
int max_towers(int L, int R, int D) {
return ruhan::calc(L, R, D, int(2e9));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4091 ms |
13388 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
592 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
592 KB |
Output is correct |
17 |
Correct |
1 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
592 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
1 ms |
592 KB |
Output is correct |
23 |
Correct |
1 ms |
720 KB |
Output is correct |
24 |
Correct |
1 ms |
720 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
592 KB |
Output is correct |
27 |
Correct |
1 ms |
592 KB |
Output is correct |
28 |
Correct |
1 ms |
592 KB |
Output is correct |
29 |
Correct |
1 ms |
592 KB |
Output is correct |
30 |
Correct |
1 ms |
592 KB |
Output is correct |
31 |
Correct |
1 ms |
592 KB |
Output is correct |
32 |
Correct |
1 ms |
720 KB |
Output is correct |
33 |
Correct |
1 ms |
592 KB |
Output is correct |
34 |
Correct |
1 ms |
592 KB |
Output is correct |
35 |
Correct |
1 ms |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
592 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
592 KB |
Output is correct |
17 |
Correct |
1 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
592 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
1 ms |
592 KB |
Output is correct |
23 |
Correct |
1 ms |
720 KB |
Output is correct |
24 |
Correct |
1 ms |
720 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
592 KB |
Output is correct |
27 |
Correct |
1 ms |
592 KB |
Output is correct |
28 |
Correct |
1 ms |
592 KB |
Output is correct |
29 |
Correct |
1 ms |
592 KB |
Output is correct |
30 |
Correct |
1 ms |
592 KB |
Output is correct |
31 |
Correct |
1 ms |
592 KB |
Output is correct |
32 |
Correct |
1 ms |
720 KB |
Output is correct |
33 |
Correct |
1 ms |
592 KB |
Output is correct |
34 |
Correct |
1 ms |
592 KB |
Output is correct |
35 |
Correct |
1 ms |
720 KB |
Output is correct |
36 |
Correct |
19 ms |
11836 KB |
Output is correct |
37 |
Correct |
28 ms |
17968 KB |
Output is correct |
38 |
Correct |
28 ms |
17948 KB |
Output is correct |
39 |
Correct |
28 ms |
17832 KB |
Output is correct |
40 |
Correct |
28 ms |
17840 KB |
Output is correct |
41 |
Correct |
30 ms |
17864 KB |
Output is correct |
42 |
Correct |
28 ms |
17956 KB |
Output is correct |
43 |
Correct |
28 ms |
19216 KB |
Output is correct |
44 |
Correct |
27 ms |
17944 KB |
Output is correct |
45 |
Correct |
27 ms |
17952 KB |
Output is correct |
46 |
Correct |
35 ms |
17948 KB |
Output is correct |
47 |
Correct |
36 ms |
17872 KB |
Output is correct |
48 |
Correct |
28 ms |
17944 KB |
Output is correct |
49 |
Correct |
37 ms |
17944 KB |
Output is correct |
50 |
Correct |
28 ms |
18440 KB |
Output is correct |
51 |
Correct |
28 ms |
19592 KB |
Output is correct |
52 |
Correct |
31 ms |
17980 KB |
Output is correct |
53 |
Correct |
28 ms |
17864 KB |
Output is correct |
54 |
Correct |
37 ms |
17944 KB |
Output is correct |
55 |
Correct |
35 ms |
23328 KB |
Output is correct |
56 |
Correct |
32 ms |
22796 KB |
Output is correct |
57 |
Correct |
28 ms |
17304 KB |
Output is correct |
58 |
Correct |
30 ms |
17852 KB |
Output is correct |
59 |
Correct |
30 ms |
17948 KB |
Output is correct |
60 |
Correct |
29 ms |
17864 KB |
Output is correct |
61 |
Correct |
28 ms |
17912 KB |
Output is correct |
62 |
Correct |
32 ms |
17952 KB |
Output is correct |
63 |
Correct |
29 ms |
17960 KB |
Output is correct |
64 |
Correct |
31 ms |
20232 KB |
Output is correct |
65 |
Correct |
29 ms |
19876 KB |
Output is correct |
66 |
Correct |
29 ms |
19488 KB |
Output is correct |
67 |
Correct |
38 ms |
19964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4075 ms |
17736 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4003 ms |
4432 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
1 ms |
592 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
592 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
592 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
592 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
592 KB |
Output is correct |
17 |
Correct |
1 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
592 KB |
Output is correct |
19 |
Correct |
1 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
592 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
1 ms |
592 KB |
Output is correct |
23 |
Correct |
1 ms |
720 KB |
Output is correct |
24 |
Correct |
1 ms |
720 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
592 KB |
Output is correct |
27 |
Correct |
1 ms |
592 KB |
Output is correct |
28 |
Correct |
1 ms |
592 KB |
Output is correct |
29 |
Correct |
1 ms |
592 KB |
Output is correct |
30 |
Correct |
1 ms |
592 KB |
Output is correct |
31 |
Correct |
1 ms |
592 KB |
Output is correct |
32 |
Correct |
1 ms |
720 KB |
Output is correct |
33 |
Correct |
1 ms |
592 KB |
Output is correct |
34 |
Correct |
1 ms |
592 KB |
Output is correct |
35 |
Correct |
1 ms |
720 KB |
Output is correct |
36 |
Correct |
19 ms |
11836 KB |
Output is correct |
37 |
Correct |
28 ms |
17968 KB |
Output is correct |
38 |
Correct |
28 ms |
17948 KB |
Output is correct |
39 |
Correct |
28 ms |
17832 KB |
Output is correct |
40 |
Correct |
28 ms |
17840 KB |
Output is correct |
41 |
Correct |
30 ms |
17864 KB |
Output is correct |
42 |
Correct |
28 ms |
17956 KB |
Output is correct |
43 |
Correct |
28 ms |
19216 KB |
Output is correct |
44 |
Correct |
27 ms |
17944 KB |
Output is correct |
45 |
Correct |
27 ms |
17952 KB |
Output is correct |
46 |
Correct |
35 ms |
17948 KB |
Output is correct |
47 |
Correct |
36 ms |
17872 KB |
Output is correct |
48 |
Correct |
28 ms |
17944 KB |
Output is correct |
49 |
Correct |
37 ms |
17944 KB |
Output is correct |
50 |
Correct |
28 ms |
18440 KB |
Output is correct |
51 |
Correct |
28 ms |
19592 KB |
Output is correct |
52 |
Correct |
31 ms |
17980 KB |
Output is correct |
53 |
Correct |
28 ms |
17864 KB |
Output is correct |
54 |
Correct |
37 ms |
17944 KB |
Output is correct |
55 |
Correct |
35 ms |
23328 KB |
Output is correct |
56 |
Correct |
32 ms |
22796 KB |
Output is correct |
57 |
Correct |
28 ms |
17304 KB |
Output is correct |
58 |
Correct |
30 ms |
17852 KB |
Output is correct |
59 |
Correct |
30 ms |
17948 KB |
Output is correct |
60 |
Correct |
29 ms |
17864 KB |
Output is correct |
61 |
Correct |
28 ms |
17912 KB |
Output is correct |
62 |
Correct |
32 ms |
17952 KB |
Output is correct |
63 |
Correct |
29 ms |
17960 KB |
Output is correct |
64 |
Correct |
31 ms |
20232 KB |
Output is correct |
65 |
Correct |
29 ms |
19876 KB |
Output is correct |
66 |
Correct |
29 ms |
19488 KB |
Output is correct |
67 |
Correct |
38 ms |
19964 KB |
Output is correct |
68 |
Execution timed out |
4075 ms |
17736 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4091 ms |
13388 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |