// AM + DG
#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vpi> vvpi;
typedef vector<vpll> vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef short int si;
typedef vector<si> vsi;
typedef vector<vsi> vvsi;
#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define L(varll, mn, mx) for(ll varll = (mn); varll < (mx); varll++)
#define LR(varll, mx, mn) for(ll varll = (mx); varll > (mn); varll--)
#define LI(vari, mn, mx) for(int vari = (mn); vari < (mx); vari++)
#define LIR(vari, mx, mn) for(int vari = (mx); vari > (mn); vari--)
#define INPV(varvec) for(auto& varveci : (varvec)) cin >> varveci
#define fi first
#define se second
#define pb push_back
#define INF(type) numeric_limits<type>::max()
#define NINF(type) numeric_limits<type>::min()
#define TCASES int t; cin >> t; while(t--)
class Tree {
public:
int l, r;
Tree *lt, *rt;
int mnv, mxv;
Tree(int a_l, int a_r): l(a_l), r(a_r), lt(nullptr), rt(nullptr), mnv(NINF(int)), mxv(INF(int)) {};
void combine() {
mnv = min(lt->mnv, rt->mnv);
mxv = max(lt->mxv, rt->mxv);
}
void build(const vi& a) {
if(l == r) {
mnv = mxv = a[l];
return;
}
int m = (l + r) >> 1;
lt = new Tree(l, m);
rt = new Tree(m + 1, r);
lt->build(a);
rt->build(a);
combine();
}
pi qry(int ql, int qr) {
if(ql > r || qr < l) return {INF(int), NINF(int)};
if(ql == l && qr == r) return {mnv, mxv};
int m = (l + r) >> 1;
auto [mn1, mx1] = lt->qry(ql, min(qr, m));
auto [mn2, mx2] = rt->qry(max(ql, m + 1), qr);
return {min(mn1, mn2), max(mx1, mx2)};
}
};
int n;
vi h_glob;
void init(int N, vi H) {
n = N;
h_glob = H;
}
int solve(vi h, int n, int d) {
Tree tr(0, n - 1);
tr.build(h);
vpi num;
for(int i = 0; i < n; i++) {
num.pb({i, h[i]});
}
sort(num.begin(), num.end(), [](pi p1, pi p2) {return p1.se < p2.se;});
// I'm pretty sure you can use ordered set, but I'm not Walsh :P
// but yes, pwede ordered set HAHA
set<pi> s;
int ans = 1;
s.insert(num[0]);
for(int i = 1; i < n; i++) {
int li = -1;
int ri = -1;
int cur_i = num[i].fi;
int cur_v = num[i].se;
auto cur_it = s.lower_bound({cur_i, cur_v});
if(cur_it != s.begin()) {
// There is a previous element!
li = prev(cur_it)->fi;
}
if(cur_it != s.end()) {
ri = cur_it->fi;
}
if((li == -1 || tr.qry(li, cur_i).se >= cur_v + d) && (ri == -1 || tr.qry(cur_i, ri).se >= cur_v + d)) {
ans++;
}
s.insert({cur_i, cur_v});
}
return ans;
}
int max_towers(int L, int R, int D) {
vi cut;
for(int i = L; i <= R; i++) {
cut.pb(h_glob[i]);
}
return solve(cut, cut.size(), D);
}
/*
The last frontier
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4077 ms |
1082996 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 |
600 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 |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
2 ms |
600 KB |
Output is correct |
29 |
Correct |
3 ms |
600 KB |
Output is correct |
30 |
Correct |
2 ms |
600 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
608 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 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 |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
2 ms |
600 KB |
Output is correct |
29 |
Correct |
3 ms |
600 KB |
Output is correct |
30 |
Correct |
2 ms |
600 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
608 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
2 ms |
600 KB |
Output is correct |
36 |
Correct |
25 ms |
3756 KB |
Output is correct |
37 |
Correct |
38 ms |
6820 KB |
Output is correct |
38 |
Correct |
20 ms |
3396 KB |
Output is correct |
39 |
Correct |
34 ms |
6240 KB |
Output is correct |
40 |
Correct |
17 ms |
3036 KB |
Output is correct |
41 |
Correct |
80 ms |
14024 KB |
Output is correct |
42 |
Correct |
9 ms |
1488 KB |
Output is correct |
43 |
Correct |
29 ms |
9160 KB |
Output is correct |
44 |
Correct |
20 ms |
3244 KB |
Output is correct |
45 |
Correct |
16 ms |
1488 KB |
Output is correct |
46 |
Correct |
9 ms |
1368 KB |
Output is correct |
47 |
Correct |
38 ms |
6600 KB |
Output is correct |
48 |
Correct |
25 ms |
4296 KB |
Output is correct |
49 |
Correct |
14 ms |
2256 KB |
Output is correct |
50 |
Correct |
16 ms |
4560 KB |
Output is correct |
51 |
Correct |
25 ms |
7376 KB |
Output is correct |
52 |
Correct |
107 ms |
16836 KB |
Output is correct |
53 |
Correct |
103 ms |
16772 KB |
Output is correct |
54 |
Correct |
103 ms |
16812 KB |
Output is correct |
55 |
Correct |
53 ms |
16792 KB |
Output is correct |
56 |
Correct |
62 ms |
17028 KB |
Output is correct |
57 |
Correct |
96 ms |
16080 KB |
Output is correct |
58 |
Correct |
99 ms |
16760 KB |
Output is correct |
59 |
Correct |
105 ms |
16836 KB |
Output is correct |
60 |
Correct |
113 ms |
16660 KB |
Output is correct |
61 |
Correct |
100 ms |
16836 KB |
Output is correct |
62 |
Correct |
99 ms |
16840 KB |
Output is correct |
63 |
Correct |
99 ms |
16836 KB |
Output is correct |
64 |
Correct |
55 ms |
16720 KB |
Output is correct |
65 |
Correct |
50 ms |
16836 KB |
Output is correct |
66 |
Correct |
48 ms |
16836 KB |
Output is correct |
67 |
Correct |
61 ms |
16820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4073 ms |
469444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4056 ms |
537416 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 |
600 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 |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
2 ms |
600 KB |
Output is correct |
29 |
Correct |
3 ms |
600 KB |
Output is correct |
30 |
Correct |
2 ms |
600 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
608 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
2 ms |
600 KB |
Output is correct |
36 |
Correct |
25 ms |
3756 KB |
Output is correct |
37 |
Correct |
38 ms |
6820 KB |
Output is correct |
38 |
Correct |
20 ms |
3396 KB |
Output is correct |
39 |
Correct |
34 ms |
6240 KB |
Output is correct |
40 |
Correct |
17 ms |
3036 KB |
Output is correct |
41 |
Correct |
80 ms |
14024 KB |
Output is correct |
42 |
Correct |
9 ms |
1488 KB |
Output is correct |
43 |
Correct |
29 ms |
9160 KB |
Output is correct |
44 |
Correct |
20 ms |
3244 KB |
Output is correct |
45 |
Correct |
16 ms |
1488 KB |
Output is correct |
46 |
Correct |
9 ms |
1368 KB |
Output is correct |
47 |
Correct |
38 ms |
6600 KB |
Output is correct |
48 |
Correct |
25 ms |
4296 KB |
Output is correct |
49 |
Correct |
14 ms |
2256 KB |
Output is correct |
50 |
Correct |
16 ms |
4560 KB |
Output is correct |
51 |
Correct |
25 ms |
7376 KB |
Output is correct |
52 |
Correct |
107 ms |
16836 KB |
Output is correct |
53 |
Correct |
103 ms |
16772 KB |
Output is correct |
54 |
Correct |
103 ms |
16812 KB |
Output is correct |
55 |
Correct |
53 ms |
16792 KB |
Output is correct |
56 |
Correct |
62 ms |
17028 KB |
Output is correct |
57 |
Correct |
96 ms |
16080 KB |
Output is correct |
58 |
Correct |
99 ms |
16760 KB |
Output is correct |
59 |
Correct |
105 ms |
16836 KB |
Output is correct |
60 |
Correct |
113 ms |
16660 KB |
Output is correct |
61 |
Correct |
100 ms |
16836 KB |
Output is correct |
62 |
Correct |
99 ms |
16840 KB |
Output is correct |
63 |
Correct |
99 ms |
16836 KB |
Output is correct |
64 |
Correct |
55 ms |
16720 KB |
Output is correct |
65 |
Correct |
50 ms |
16836 KB |
Output is correct |
66 |
Correct |
48 ms |
16836 KB |
Output is correct |
67 |
Correct |
61 ms |
16820 KB |
Output is correct |
68 |
Execution timed out |
4073 ms |
469444 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4077 ms |
1082996 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |