#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
int n;
vi H, Hord;
map<int, int> NorMap;
void init(int n, vi H0) {
::n = n;
H = H0;
Hord = H;
sort(Hord.begin(), Hord.end());
Hord.resize(unique(Hord.begin(), Hord.end()) - Hord.begin());
for(int i = 0; i < (int)Hord.size(); ++i)
NorMap[Hord[i]] = i;
}
struct AIB { // max pe prefixe
int n;
vi V;
AIB(int N) : n(N + 2), V(N + 2, -1) {}
void update(int p, int v) {
++p;
while(p < n) {
V[p] = max(V[p], v);
p += p & -p;
}
}
int query(int p) {
++p;
if( p < 0 ) return 0;
int re = 0;
while(p) {
re = max(re, V[p]);
p -= p & -p;
}
return re;
}
};
struct maxSuf {
int n;
AIB A;
maxSuf(int N) : n(N + 1), A(N + 1) {}
void update(int p, int v) { A.update(n - p - 1, v); }
int query(int p) { return A.query(n - p - 1); }
};
int max_towers(int l, int r, int D) {
vi DP0(n, 1), DP1(n, 0);
///DP0, ult e statie. DP1 ult e turn
AIB MP(n);
maxSuf MS(n);
int re = 1;
for (int i = l; i <= r; ++i) {
int y = H[i];
if(Hord[0] + D <= y) { /// merita cautat
//leg un turn la ceva mai mic
int st = 0, dr = int(Hord.size()) - 1, mij;
while(st < dr) {
mij = (st + dr + 1) / 2;
if(Hord[mij] + D <= y) st = mij;
else dr = mij - 1;
}
DP1[i] = max(DP1[i], 1 + MP.query(st));
}
MS.update(NorMap[y], DP1[i]);
if(Hord.back() - D >= y) {
int st = 0, dr = int(Hord.size()) - 1, mij;
while(st < dr) {
mij = (st + dr) / 2;
if(Hord[mij] - D >= y) {
dr = mij;
} else st = mij + 1;
}
DP0[i] = max(DP0[i], MS.query(st) + 1);
}
MP.update(NorMap[y], DP0[i]);
re = max(re, (DP0[i] + 1) / 2);
}
return re;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4043 ms |
5068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 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 |
1 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 |
548 KB |
Output is correct |
27 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
560 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 |
1 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 |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 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 |
1 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 |
548 KB |
Output is correct |
27 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
560 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 |
27 ms |
5208 KB |
Output is correct |
37 |
Correct |
43 ms |
7632 KB |
Output is correct |
38 |
Correct |
32 ms |
7624 KB |
Output is correct |
39 |
Correct |
34 ms |
7632 KB |
Output is correct |
40 |
Correct |
30 ms |
7632 KB |
Output is correct |
41 |
Correct |
68 ms |
7632 KB |
Output is correct |
42 |
Correct |
25 ms |
7632 KB |
Output is correct |
43 |
Correct |
31 ms |
7632 KB |
Output is correct |
44 |
Correct |
33 ms |
7788 KB |
Output is correct |
45 |
Correct |
19 ms |
7628 KB |
Output is correct |
46 |
Correct |
22 ms |
7632 KB |
Output is correct |
47 |
Correct |
51 ms |
7632 KB |
Output is correct |
48 |
Correct |
36 ms |
7632 KB |
Output is correct |
49 |
Correct |
34 ms |
7612 KB |
Output is correct |
50 |
Correct |
24 ms |
7628 KB |
Output is correct |
51 |
Correct |
28 ms |
7632 KB |
Output is correct |
52 |
Correct |
78 ms |
7856 KB |
Output is correct |
53 |
Correct |
76 ms |
7632 KB |
Output is correct |
54 |
Correct |
75 ms |
7632 KB |
Output is correct |
55 |
Correct |
42 ms |
7632 KB |
Output is correct |
56 |
Correct |
47 ms |
7632 KB |
Output is correct |
57 |
Correct |
61 ms |
7388 KB |
Output is correct |
58 |
Correct |
67 ms |
7632 KB |
Output is correct |
59 |
Correct |
72 ms |
7632 KB |
Output is correct |
60 |
Correct |
78 ms |
7624 KB |
Output is correct |
61 |
Correct |
73 ms |
7632 KB |
Output is correct |
62 |
Correct |
71 ms |
7624 KB |
Output is correct |
63 |
Correct |
74 ms |
7624 KB |
Output is correct |
64 |
Correct |
40 ms |
7632 KB |
Output is correct |
65 |
Correct |
35 ms |
7632 KB |
Output is correct |
66 |
Correct |
43 ms |
7888 KB |
Output is correct |
67 |
Correct |
37 ms |
7632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4056 ms |
7816 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4045 ms |
2512 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 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 |
1 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 |
548 KB |
Output is correct |
27 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
560 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 |
27 ms |
5208 KB |
Output is correct |
37 |
Correct |
43 ms |
7632 KB |
Output is correct |
38 |
Correct |
32 ms |
7624 KB |
Output is correct |
39 |
Correct |
34 ms |
7632 KB |
Output is correct |
40 |
Correct |
30 ms |
7632 KB |
Output is correct |
41 |
Correct |
68 ms |
7632 KB |
Output is correct |
42 |
Correct |
25 ms |
7632 KB |
Output is correct |
43 |
Correct |
31 ms |
7632 KB |
Output is correct |
44 |
Correct |
33 ms |
7788 KB |
Output is correct |
45 |
Correct |
19 ms |
7628 KB |
Output is correct |
46 |
Correct |
22 ms |
7632 KB |
Output is correct |
47 |
Correct |
51 ms |
7632 KB |
Output is correct |
48 |
Correct |
36 ms |
7632 KB |
Output is correct |
49 |
Correct |
34 ms |
7612 KB |
Output is correct |
50 |
Correct |
24 ms |
7628 KB |
Output is correct |
51 |
Correct |
28 ms |
7632 KB |
Output is correct |
52 |
Correct |
78 ms |
7856 KB |
Output is correct |
53 |
Correct |
76 ms |
7632 KB |
Output is correct |
54 |
Correct |
75 ms |
7632 KB |
Output is correct |
55 |
Correct |
42 ms |
7632 KB |
Output is correct |
56 |
Correct |
47 ms |
7632 KB |
Output is correct |
57 |
Correct |
61 ms |
7388 KB |
Output is correct |
58 |
Correct |
67 ms |
7632 KB |
Output is correct |
59 |
Correct |
72 ms |
7632 KB |
Output is correct |
60 |
Correct |
78 ms |
7624 KB |
Output is correct |
61 |
Correct |
73 ms |
7632 KB |
Output is correct |
62 |
Correct |
71 ms |
7624 KB |
Output is correct |
63 |
Correct |
74 ms |
7624 KB |
Output is correct |
64 |
Correct |
40 ms |
7632 KB |
Output is correct |
65 |
Correct |
35 ms |
7632 KB |
Output is correct |
66 |
Correct |
43 ms |
7888 KB |
Output is correct |
67 |
Correct |
37 ms |
7632 KB |
Output is correct |
68 |
Execution timed out |
4056 ms |
7816 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4043 ms |
5068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |