#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + 100;
int n;
int a[maxn];
int t[maxn];
int dp[maxn];
vector<pii> g[maxn];
int l[maxn];
int r[maxn];
void upd(int i, int x){
for(; i <= n; i |= (i + 1)) t[i] = max(t[i], x);
}
int get(int i){
int res = 0;
for(; i > 0; i = (i & (i + 1)) - 1) res = max(res, t[i]);
return res;
}
void init(int N, std::vector<int> H){
n = N;
for(int i = 1; i <= n; i++){
a[i] = H[i-1];
}
}
int max_towers(int L, int R, int D){
L++; R++;
for(int i = 1; i <= n; i++){
t[i] = 0;
g[i].clear();
}
vector<int> v;
for(int i = L; i <= R; i++){
while(v.size() && a[v.back()] <= a[i]) v.pop_back();
v.push_back(i);
l[i] = L - 1;
for(int tl = 0, tr = v.size() - 1; tl <= tr;){
int mid = (tl + tr) >> 1;
if(a[v[mid]] - D < a[i]) tr = mid - 1;
else tl = mid + 1, l[i] = v[mid];
}
}
v.clear();
for(int i = R; i >= L; i--){
while(v.size() && a[v.back()] <= a[i]) v.pop_back();
v.push_back(i);
r[i] = R + 1;
for(int tl = 0, tr = v.size() - 1; tl <= tr;){
int mid = (tl + tr) >> 1;
if(a[v[mid]] - D < a[i]) tr = mid - 1;
else tl = mid + 1, r[i] = v[mid];
}
}
int ans = 0;
for(int i = L; i <= R; i++){
for(auto [p, x]: g[i]){
upd(p, x);
}
dp[i] = get(l[i]) + 1;
g[r[i]].push_back({i, dp[i]});
ans = max(ans, dp[i]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4083 ms |
516544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
2760 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
2 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
2 ms |
2808 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
2 ms |
2648 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2648 KB |
Output is correct |
23 |
Correct |
2 ms |
2648 KB |
Output is correct |
24 |
Correct |
2 ms |
2904 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
2 ms |
2648 KB |
Output is correct |
28 |
Correct |
2 ms |
2904 KB |
Output is correct |
29 |
Correct |
2 ms |
2648 KB |
Output is correct |
30 |
Correct |
1 ms |
2648 KB |
Output is correct |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2740 KB |
Output is correct |
33 |
Correct |
2 ms |
2648 KB |
Output is correct |
34 |
Correct |
2 ms |
2904 KB |
Output is correct |
35 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
2760 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
2 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
2 ms |
2808 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
2 ms |
2648 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2648 KB |
Output is correct |
23 |
Correct |
2 ms |
2648 KB |
Output is correct |
24 |
Correct |
2 ms |
2904 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
2 ms |
2648 KB |
Output is correct |
28 |
Correct |
2 ms |
2904 KB |
Output is correct |
29 |
Correct |
2 ms |
2648 KB |
Output is correct |
30 |
Correct |
1 ms |
2648 KB |
Output is correct |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2740 KB |
Output is correct |
33 |
Correct |
2 ms |
2648 KB |
Output is correct |
34 |
Correct |
2 ms |
2904 KB |
Output is correct |
35 |
Correct |
1 ms |
2648 KB |
Output is correct |
36 |
Correct |
9 ms |
4180 KB |
Output is correct |
37 |
Correct |
21 ms |
4808 KB |
Output is correct |
38 |
Correct |
12 ms |
4304 KB |
Output is correct |
39 |
Correct |
11 ms |
4816 KB |
Output is correct |
40 |
Correct |
12 ms |
4304 KB |
Output is correct |
41 |
Correct |
16 ms |
5980 KB |
Output is correct |
42 |
Correct |
11 ms |
4048 KB |
Output is correct |
43 |
Correct |
18 ms |
5584 KB |
Output is correct |
44 |
Correct |
10 ms |
4196 KB |
Output is correct |
45 |
Correct |
15 ms |
4048 KB |
Output is correct |
46 |
Correct |
10 ms |
4048 KB |
Output is correct |
47 |
Correct |
14 ms |
5016 KB |
Output is correct |
48 |
Correct |
13 ms |
4560 KB |
Output is correct |
49 |
Correct |
11 ms |
4048 KB |
Output is correct |
50 |
Correct |
11 ms |
4716 KB |
Output is correct |
51 |
Correct |
13 ms |
5840 KB |
Output is correct |
52 |
Correct |
29 ms |
6896 KB |
Output is correct |
53 |
Correct |
27 ms |
6900 KB |
Output is correct |
54 |
Correct |
20 ms |
6784 KB |
Output is correct |
55 |
Correct |
14 ms |
6908 KB |
Output is correct |
56 |
Correct |
18 ms |
8400 KB |
Output is correct |
57 |
Correct |
17 ms |
6108 KB |
Output is correct |
58 |
Correct |
19 ms |
6244 KB |
Output is correct |
59 |
Correct |
21 ms |
6600 KB |
Output is correct |
60 |
Correct |
19 ms |
6908 KB |
Output is correct |
61 |
Correct |
19 ms |
6864 KB |
Output is correct |
62 |
Correct |
18 ms |
6608 KB |
Output is correct |
63 |
Correct |
19 ms |
6856 KB |
Output is correct |
64 |
Correct |
18 ms |
7164 KB |
Output is correct |
65 |
Correct |
20 ms |
6864 KB |
Output is correct |
66 |
Correct |
18 ms |
6864 KB |
Output is correct |
67 |
Correct |
15 ms |
6864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4018 ms |
7260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4102 ms |
266908 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
2 ms |
2760 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
2 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
2 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
2 ms |
2808 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
2 ms |
2648 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
2 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2648 KB |
Output is correct |
23 |
Correct |
2 ms |
2648 KB |
Output is correct |
24 |
Correct |
2 ms |
2904 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
2 ms |
2648 KB |
Output is correct |
28 |
Correct |
2 ms |
2904 KB |
Output is correct |
29 |
Correct |
2 ms |
2648 KB |
Output is correct |
30 |
Correct |
1 ms |
2648 KB |
Output is correct |
31 |
Correct |
2 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2740 KB |
Output is correct |
33 |
Correct |
2 ms |
2648 KB |
Output is correct |
34 |
Correct |
2 ms |
2904 KB |
Output is correct |
35 |
Correct |
1 ms |
2648 KB |
Output is correct |
36 |
Correct |
9 ms |
4180 KB |
Output is correct |
37 |
Correct |
21 ms |
4808 KB |
Output is correct |
38 |
Correct |
12 ms |
4304 KB |
Output is correct |
39 |
Correct |
11 ms |
4816 KB |
Output is correct |
40 |
Correct |
12 ms |
4304 KB |
Output is correct |
41 |
Correct |
16 ms |
5980 KB |
Output is correct |
42 |
Correct |
11 ms |
4048 KB |
Output is correct |
43 |
Correct |
18 ms |
5584 KB |
Output is correct |
44 |
Correct |
10 ms |
4196 KB |
Output is correct |
45 |
Correct |
15 ms |
4048 KB |
Output is correct |
46 |
Correct |
10 ms |
4048 KB |
Output is correct |
47 |
Correct |
14 ms |
5016 KB |
Output is correct |
48 |
Correct |
13 ms |
4560 KB |
Output is correct |
49 |
Correct |
11 ms |
4048 KB |
Output is correct |
50 |
Correct |
11 ms |
4716 KB |
Output is correct |
51 |
Correct |
13 ms |
5840 KB |
Output is correct |
52 |
Correct |
29 ms |
6896 KB |
Output is correct |
53 |
Correct |
27 ms |
6900 KB |
Output is correct |
54 |
Correct |
20 ms |
6784 KB |
Output is correct |
55 |
Correct |
14 ms |
6908 KB |
Output is correct |
56 |
Correct |
18 ms |
8400 KB |
Output is correct |
57 |
Correct |
17 ms |
6108 KB |
Output is correct |
58 |
Correct |
19 ms |
6244 KB |
Output is correct |
59 |
Correct |
21 ms |
6600 KB |
Output is correct |
60 |
Correct |
19 ms |
6908 KB |
Output is correct |
61 |
Correct |
19 ms |
6864 KB |
Output is correct |
62 |
Correct |
18 ms |
6608 KB |
Output is correct |
63 |
Correct |
19 ms |
6856 KB |
Output is correct |
64 |
Correct |
18 ms |
7164 KB |
Output is correct |
65 |
Correct |
20 ms |
6864 KB |
Output is correct |
66 |
Correct |
18 ms |
6864 KB |
Output is correct |
67 |
Correct |
15 ms |
6864 KB |
Output is correct |
68 |
Execution timed out |
4018 ms |
7260 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4083 ms |
516544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |