#include <bits/stdc++.h>
using namespace std;
using i32 = int;
using i64 = long long;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T>>;
template <typename T>
using VVV = V<V<V<T>>>;
template <typename T>
bool chmin(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
#define OVERRIDE4(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, l, r) for (i32 i = (i32)(l); i < (i32)(r); ++i)
#define REP(...) OVERRIDE4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER2(i, n) for (i32 i = (i32)(n)-1; i >= 0; --i)
#define PER3(i, l, r) for (i32 i = (i32)(r)-1; i >= (i32)(l); --i)
#define PER(...) OVERRIDE4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__)
#define ALL(x) begin(x), end(x)
#define LEN(x) (i32) size(x)
void dbg(i32 x) { cerr << x; }
void dbg(i64 x) { cerr << x; }
template <typename T, typename U>
void dbg(pair<T, U> p) {
cerr << '(' << p.first << ", " << p.second << ')';
}
template <typename T>
void dbg(V<T> arr) {
cerr << '[';
REP(i, LEN(arr)) {
if (i) {
cerr << ", ";
}
dbg(arr[i]);
}
cerr << ']';
}
void debug() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug(Head head, Tail... tail) {
dbg(head);
cerr << ", ";
debug(tail...);
}
#ifdef DEBUGF
#define DBG(...) \
do { \
cerr << #__VA_ARGS__ << " : "; \
debug(__VA_ARGS__); \
} while (false)
#else
#define DBG(...) (void)0
#endif
#include "towers.h"
constexpr i32 INF = 1001001001;
template <typename T>
i32 lob(const V<T> &arr, T v) {
return (i32)(lower_bound(ALL(arr), v) - begin(arr));
}
template <typename T>
i32 upb(const V<T> &arr, T v) {
return (i32)(upper_bound(ALL(arr), v) - begin(arr));
}
struct RMQ {
i32 n;
V<i32> dat;
RMQ(i32 n) : n(n), dat(2 * n, -INF) {}
void update(i32 idx, i32 val) {
idx += n;
dat[idx] = val;
while ((idx /= 2) >= 1) {
dat[idx] = max(dat[2 * idx], dat[2 * idx + 1]);
}
}
i32 rmq(i32 l, i32 r) const {
l += n;
r += n;
i32 m = -INF;
while (l < r) {
if (l & 1) {
chmax(m, dat[l++]);
}
if (r & 1) {
chmax(m, dat[--r]);
}
l /= 2;
r /= 2;
}
return m;
}
void trc() const {
V<i32> arr(n + ALL(dat));
DBG(arr);
}
};
i32 n;
V<i32> h;
void init(i32 _n, V<i32> _h) {
n = _n;
h = _h;
}
i32 max_towers(i32 l, i32 r, i32 delta) {
++r;
V<i32> g(begin(h) + l, begin(h) + r);
i32 m = r - l;
V<i32> hs;
hs.reserve(3 * m);
REP(i, m) {
hs.push_back(g[i] - delta);
hs.push_back(g[i]);
hs.push_back(g[i] + delta);
}
sort(ALL(hs));
hs.erase(unique(ALL(hs)), end(hs));
i32 k = LEN(hs);
RMQ down(k);
RMQ up(k);
REP(i, m) {
i32 d = max(1, up.rmq(lob(hs, g[i] + delta), k) + 1);
i32 u = down.rmq(0, lob(hs, g[i] - delta) + 1);
i32 idx = lob(hs, g[i]);
down.update(idx, d);
up.update(idx, u);
}
i32 ans = down.rmq(0, k);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4050 ms |
4624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
372 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
372 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
372 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
372 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
15 ms |
1880 KB |
Output is correct |
37 |
Correct |
29 ms |
3280 KB |
Output is correct |
38 |
Correct |
14 ms |
2000 KB |
Output is correct |
39 |
Correct |
31 ms |
3024 KB |
Output is correct |
40 |
Correct |
16 ms |
1976 KB |
Output is correct |
41 |
Correct |
65 ms |
6332 KB |
Output is correct |
42 |
Correct |
14 ms |
1368 KB |
Output is correct |
43 |
Correct |
31 ms |
4400 KB |
Output is correct |
44 |
Correct |
11 ms |
2000 KB |
Output is correct |
45 |
Correct |
13 ms |
1368 KB |
Output is correct |
46 |
Correct |
7 ms |
1368 KB |
Output is correct |
47 |
Correct |
26 ms |
3280 KB |
Output is correct |
48 |
Correct |
17 ms |
2512 KB |
Output is correct |
49 |
Correct |
11 ms |
1488 KB |
Output is correct |
50 |
Correct |
13 ms |
2340 KB |
Output is correct |
51 |
Correct |
20 ms |
3536 KB |
Output is correct |
52 |
Correct |
68 ms |
7376 KB |
Output is correct |
53 |
Correct |
66 ms |
7376 KB |
Output is correct |
54 |
Correct |
67 ms |
7376 KB |
Output is correct |
55 |
Correct |
39 ms |
7376 KB |
Output is correct |
56 |
Correct |
39 ms |
7376 KB |
Output is correct |
57 |
Correct |
75 ms |
7340 KB |
Output is correct |
58 |
Correct |
74 ms |
7376 KB |
Output is correct |
59 |
Correct |
83 ms |
7464 KB |
Output is correct |
60 |
Correct |
87 ms |
7400 KB |
Output is correct |
61 |
Correct |
74 ms |
7376 KB |
Output is correct |
62 |
Correct |
74 ms |
7464 KB |
Output is correct |
63 |
Correct |
76 ms |
7396 KB |
Output is correct |
64 |
Correct |
42 ms |
7376 KB |
Output is correct |
65 |
Correct |
44 ms |
7372 KB |
Output is correct |
66 |
Correct |
49 ms |
7376 KB |
Output is correct |
67 |
Correct |
43 ms |
7376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4043 ms |
8600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4022 ms |
2316 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
372 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
2 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
372 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
15 ms |
1880 KB |
Output is correct |
37 |
Correct |
29 ms |
3280 KB |
Output is correct |
38 |
Correct |
14 ms |
2000 KB |
Output is correct |
39 |
Correct |
31 ms |
3024 KB |
Output is correct |
40 |
Correct |
16 ms |
1976 KB |
Output is correct |
41 |
Correct |
65 ms |
6332 KB |
Output is correct |
42 |
Correct |
14 ms |
1368 KB |
Output is correct |
43 |
Correct |
31 ms |
4400 KB |
Output is correct |
44 |
Correct |
11 ms |
2000 KB |
Output is correct |
45 |
Correct |
13 ms |
1368 KB |
Output is correct |
46 |
Correct |
7 ms |
1368 KB |
Output is correct |
47 |
Correct |
26 ms |
3280 KB |
Output is correct |
48 |
Correct |
17 ms |
2512 KB |
Output is correct |
49 |
Correct |
11 ms |
1488 KB |
Output is correct |
50 |
Correct |
13 ms |
2340 KB |
Output is correct |
51 |
Correct |
20 ms |
3536 KB |
Output is correct |
52 |
Correct |
68 ms |
7376 KB |
Output is correct |
53 |
Correct |
66 ms |
7376 KB |
Output is correct |
54 |
Correct |
67 ms |
7376 KB |
Output is correct |
55 |
Correct |
39 ms |
7376 KB |
Output is correct |
56 |
Correct |
39 ms |
7376 KB |
Output is correct |
57 |
Correct |
75 ms |
7340 KB |
Output is correct |
58 |
Correct |
74 ms |
7376 KB |
Output is correct |
59 |
Correct |
83 ms |
7464 KB |
Output is correct |
60 |
Correct |
87 ms |
7400 KB |
Output is correct |
61 |
Correct |
74 ms |
7376 KB |
Output is correct |
62 |
Correct |
74 ms |
7464 KB |
Output is correct |
63 |
Correct |
76 ms |
7396 KB |
Output is correct |
64 |
Correct |
42 ms |
7376 KB |
Output is correct |
65 |
Correct |
44 ms |
7372 KB |
Output is correct |
66 |
Correct |
49 ms |
7376 KB |
Output is correct |
67 |
Correct |
43 ms |
7376 KB |
Output is correct |
68 |
Execution timed out |
4043 ms |
8600 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4050 ms |
4624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |