#include "towers.h"
#include <bits/stdc++.h>
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define fe(x, y) for (auto& x : y)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define pw(x) (1LL << (x))
#define sz(x) (int)x.size()
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ve = vector <T>;
template <typename T>
bool umx (T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T>
bool umn (T& a, T b) { return a > b ? a = b, 1 : 0; }
using ll = long long;
using ld = long double;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
using ull = unsigned long long;
const int oo = 1e9;
const ll OO = 1e18;
const int N = 1e5 + 10;
const int M = 5e3 + 100;
const int mod = 1e9 + 7;
const bool TEST = 0;
int spars[N][20];
int h[N];
int get(int l, int r) {
int sz = r - l + 1;
return max(spars[l][__lg(sz)], spars[r - pw(__lg(sz)) + 1][__lg(sz)]);
}
void init(int N, std::vector<int> H) {
for (int i = 0; i < N; i++) h[i] = spars[i][0] = H[i];
for (int bt = 1; pw(bt) <= N; bt++) {
for (int i = 0; i <= N - pw(bt); i++) {
spars[i][bt] = max(spars[i][bt - 1], spars[i + pw(bt - 1)][bt - 1]);
}
}
}
int max_towers(int L, int R, int D) {
ve <pii> V;
for (int i = L; i <= R; i++) V.pb({h[i], i});
sort(all(V));
set <int> HAVE;
for (int i = 0; i < sz(V); i++) {
if (!sz(HAVE)) {
HAVE.insert(V[i].se);
continue;
}
auto ps = HAVE.lower_bound(V[i].se);
bool ok = 1;
if (ps != HAVE.begin()) {
--ps;
int y = *ps;
++ps;
int mx = get(y, V[i].se);
ok &= (mx - D >= V[i].fi);
}
if (ps != HAVE.end()) {
int y = *ps;
int mx = get(V[i].se, y);
ok &= (mx - D >= V[i].fi);
}
if (ok) HAVE.insert(V[i].se);
}
return sz(HAVE);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4014 ms |
6524 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
408 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
2 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
464 KB |
Output is correct |
34 |
Correct |
1 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
408 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
2 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
464 KB |
Output is correct |
34 |
Correct |
1 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
17 ms |
6224 KB |
Output is correct |
37 |
Correct |
22 ms |
9692 KB |
Output is correct |
38 |
Correct |
17 ms |
9264 KB |
Output is correct |
39 |
Correct |
18 ms |
9412 KB |
Output is correct |
40 |
Correct |
18 ms |
9248 KB |
Output is correct |
41 |
Correct |
38 ms |
10384 KB |
Output is correct |
42 |
Correct |
16 ms |
9236 KB |
Output is correct |
43 |
Correct |
15 ms |
9760 KB |
Output is correct |
44 |
Correct |
14 ms |
9248 KB |
Output is correct |
45 |
Correct |
14 ms |
9292 KB |
Output is correct |
46 |
Correct |
15 ms |
9264 KB |
Output is correct |
47 |
Correct |
28 ms |
9692 KB |
Output is correct |
48 |
Correct |
19 ms |
9464 KB |
Output is correct |
49 |
Correct |
22 ms |
9248 KB |
Output is correct |
50 |
Correct |
15 ms |
9324 KB |
Output is correct |
51 |
Correct |
23 ms |
9640 KB |
Output is correct |
52 |
Correct |
52 ms |
11176 KB |
Output is correct |
53 |
Correct |
72 ms |
12000 KB |
Output is correct |
54 |
Correct |
46 ms |
11964 KB |
Output is correct |
55 |
Correct |
16 ms |
10404 KB |
Output is correct |
56 |
Correct |
24 ms |
10432 KB |
Output is correct |
57 |
Correct |
36 ms |
10148 KB |
Output is correct |
58 |
Correct |
49 ms |
10536 KB |
Output is correct |
59 |
Correct |
43 ms |
10748 KB |
Output is correct |
60 |
Correct |
54 ms |
11992 KB |
Output is correct |
61 |
Correct |
45 ms |
11556 KB |
Output is correct |
62 |
Correct |
51 ms |
11052 KB |
Output is correct |
63 |
Correct |
66 ms |
11676 KB |
Output is correct |
64 |
Correct |
18 ms |
10408 KB |
Output is correct |
65 |
Correct |
19 ms |
10436 KB |
Output is correct |
66 |
Correct |
17 ms |
10392 KB |
Output is correct |
67 |
Correct |
16 ms |
10436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4091 ms |
11540 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4094 ms |
3304 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
408 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
2 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
464 KB |
Output is correct |
34 |
Correct |
1 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
17 ms |
6224 KB |
Output is correct |
37 |
Correct |
22 ms |
9692 KB |
Output is correct |
38 |
Correct |
17 ms |
9264 KB |
Output is correct |
39 |
Correct |
18 ms |
9412 KB |
Output is correct |
40 |
Correct |
18 ms |
9248 KB |
Output is correct |
41 |
Correct |
38 ms |
10384 KB |
Output is correct |
42 |
Correct |
16 ms |
9236 KB |
Output is correct |
43 |
Correct |
15 ms |
9760 KB |
Output is correct |
44 |
Correct |
14 ms |
9248 KB |
Output is correct |
45 |
Correct |
14 ms |
9292 KB |
Output is correct |
46 |
Correct |
15 ms |
9264 KB |
Output is correct |
47 |
Correct |
28 ms |
9692 KB |
Output is correct |
48 |
Correct |
19 ms |
9464 KB |
Output is correct |
49 |
Correct |
22 ms |
9248 KB |
Output is correct |
50 |
Correct |
15 ms |
9324 KB |
Output is correct |
51 |
Correct |
23 ms |
9640 KB |
Output is correct |
52 |
Correct |
52 ms |
11176 KB |
Output is correct |
53 |
Correct |
72 ms |
12000 KB |
Output is correct |
54 |
Correct |
46 ms |
11964 KB |
Output is correct |
55 |
Correct |
16 ms |
10404 KB |
Output is correct |
56 |
Correct |
24 ms |
10432 KB |
Output is correct |
57 |
Correct |
36 ms |
10148 KB |
Output is correct |
58 |
Correct |
49 ms |
10536 KB |
Output is correct |
59 |
Correct |
43 ms |
10748 KB |
Output is correct |
60 |
Correct |
54 ms |
11992 KB |
Output is correct |
61 |
Correct |
45 ms |
11556 KB |
Output is correct |
62 |
Correct |
51 ms |
11052 KB |
Output is correct |
63 |
Correct |
66 ms |
11676 KB |
Output is correct |
64 |
Correct |
18 ms |
10408 KB |
Output is correct |
65 |
Correct |
19 ms |
10436 KB |
Output is correct |
66 |
Correct |
17 ms |
10392 KB |
Output is correct |
67 |
Correct |
16 ms |
10436 KB |
Output is correct |
68 |
Execution timed out |
4091 ms |
11540 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4014 ms |
6524 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |