#include <bits/stdc++.h>
#include "towers.h"
using namespace std;
const int INF = 2e9;
struct Node {
int mini, arg_max;
};
class Tournament {
int n, offset;
vector <int> vals;
vector <Node> tour;
public:
Node merge(Node lhs, Node rhs) const {
return {min(lhs.mini, rhs.mini), vals[lhs.arg_max] > vals[rhs.arg_max] ? lhs.arg_max : rhs.arg_max};
}
Tournament(int n, vector <int> _vals) : n(n), vals(_vals) {
vals.push_back(0);
for (offset = 1; offset <= n; offset *= 2);
tour.resize(2 * offset);
vals.resize(offset);
for (int i = 0; i < offset; i++)
tour[i + offset] = {vals[i], i};
for (int i = offset - 1; i; i--)
tour[i] = merge(tour[2 * i], tour[2 * i + 1]);
}
Tournament() {}
Node query(int x, int lo, int hi, int from, int to) const {
if (lo >= to || hi <= from)
return {INF, n};
if (lo >= from && hi <= to)
return tour[x];
int mid = (lo + hi) / 2;
return merge(query(2 * x, lo, mid, from, to), query(2 * x + 1, mid, hi, from, to));
}
Node query(int from, int to) const {
return query(1, 0, offset, from, to);
}
int get(int x) const {
return vals[x];
}
};
Tournament solver;
void init(int N, vector <int> h) {
solver = Tournament(N, h);
}
int solve(int lo, int hi, int ub, int diff) {
if (lo >= hi)
return 0;
Node tmp = solver.query(lo, hi);
if (tmp.mini > ub)
return 0;
int mid = tmp.arg_max;
int maks = solver.get(mid);
return max(solve(lo, mid, maks - diff, diff) + solve(mid + 1, hi, maks - diff, diff), 1);
}
int max_towers(int l, int r, int d) {
return solve(l, r + 1, 2e9, d);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4048 ms |
6092 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
0 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 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 |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
0 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 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 |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
10 ms |
2332 KB |
Output is correct |
37 |
Correct |
15 ms |
3976 KB |
Output is correct |
38 |
Correct |
13 ms |
3992 KB |
Output is correct |
39 |
Correct |
12 ms |
4000 KB |
Output is correct |
40 |
Correct |
14 ms |
4040 KB |
Output is correct |
41 |
Correct |
22 ms |
3984 KB |
Output is correct |
42 |
Correct |
12 ms |
3996 KB |
Output is correct |
43 |
Correct |
19 ms |
6304 KB |
Output is correct |
44 |
Correct |
12 ms |
3984 KB |
Output is correct |
45 |
Correct |
13 ms |
3984 KB |
Output is correct |
46 |
Correct |
21 ms |
3988 KB |
Output is correct |
47 |
Correct |
19 ms |
4012 KB |
Output is correct |
48 |
Correct |
15 ms |
3988 KB |
Output is correct |
49 |
Correct |
15 ms |
4040 KB |
Output is correct |
50 |
Correct |
16 ms |
5296 KB |
Output is correct |
51 |
Correct |
20 ms |
6832 KB |
Output is correct |
52 |
Correct |
35 ms |
4000 KB |
Output is correct |
53 |
Correct |
24 ms |
3996 KB |
Output is correct |
54 |
Correct |
25 ms |
3988 KB |
Output is correct |
55 |
Correct |
42 ms |
12624 KB |
Output is correct |
56 |
Correct |
30 ms |
11776 KB |
Output is correct |
57 |
Correct |
27 ms |
3916 KB |
Output is correct |
58 |
Correct |
24 ms |
4012 KB |
Output is correct |
59 |
Correct |
25 ms |
3996 KB |
Output is correct |
60 |
Correct |
25 ms |
3988 KB |
Output is correct |
61 |
Correct |
34 ms |
4000 KB |
Output is correct |
62 |
Correct |
25 ms |
4012 KB |
Output is correct |
63 |
Correct |
26 ms |
4008 KB |
Output is correct |
64 |
Correct |
21 ms |
7808 KB |
Output is correct |
65 |
Correct |
22 ms |
7464 KB |
Output is correct |
66 |
Correct |
20 ms |
6712 KB |
Output is correct |
67 |
Correct |
21 ms |
7544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4088 ms |
3920 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4030 ms |
1232 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
0 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
0 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 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 |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
10 ms |
2332 KB |
Output is correct |
37 |
Correct |
15 ms |
3976 KB |
Output is correct |
38 |
Correct |
13 ms |
3992 KB |
Output is correct |
39 |
Correct |
12 ms |
4000 KB |
Output is correct |
40 |
Correct |
14 ms |
4040 KB |
Output is correct |
41 |
Correct |
22 ms |
3984 KB |
Output is correct |
42 |
Correct |
12 ms |
3996 KB |
Output is correct |
43 |
Correct |
19 ms |
6304 KB |
Output is correct |
44 |
Correct |
12 ms |
3984 KB |
Output is correct |
45 |
Correct |
13 ms |
3984 KB |
Output is correct |
46 |
Correct |
21 ms |
3988 KB |
Output is correct |
47 |
Correct |
19 ms |
4012 KB |
Output is correct |
48 |
Correct |
15 ms |
3988 KB |
Output is correct |
49 |
Correct |
15 ms |
4040 KB |
Output is correct |
50 |
Correct |
16 ms |
5296 KB |
Output is correct |
51 |
Correct |
20 ms |
6832 KB |
Output is correct |
52 |
Correct |
35 ms |
4000 KB |
Output is correct |
53 |
Correct |
24 ms |
3996 KB |
Output is correct |
54 |
Correct |
25 ms |
3988 KB |
Output is correct |
55 |
Correct |
42 ms |
12624 KB |
Output is correct |
56 |
Correct |
30 ms |
11776 KB |
Output is correct |
57 |
Correct |
27 ms |
3916 KB |
Output is correct |
58 |
Correct |
24 ms |
4012 KB |
Output is correct |
59 |
Correct |
25 ms |
3996 KB |
Output is correct |
60 |
Correct |
25 ms |
3988 KB |
Output is correct |
61 |
Correct |
34 ms |
4000 KB |
Output is correct |
62 |
Correct |
25 ms |
4012 KB |
Output is correct |
63 |
Correct |
26 ms |
4008 KB |
Output is correct |
64 |
Correct |
21 ms |
7808 KB |
Output is correct |
65 |
Correct |
22 ms |
7464 KB |
Output is correct |
66 |
Correct |
20 ms |
6712 KB |
Output is correct |
67 |
Correct |
21 ms |
7544 KB |
Output is correct |
68 |
Execution timed out |
4088 ms |
3920 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4048 ms |
6092 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |