#include "towers.h"
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)
#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)
#define NN 100010
#define M 1000000007 // 998244353
ll h[NN];
ll n;
namespace seg {
typedef pl T;
T id={-1, -1};
T f(T a, T b) {return max(a, b);}
T t[2 * NN];
ll n=NN; // array size
void init(ll p, ll value) { // set value at position p
for (p+=n, t[p].K = value; p /= 2;) t[p] = f(t[2*p], t[2*p+1]);
}
void modify(ll p, ll value) { // set value at position p
for (p+=n, t[p].V = max(t[p].V, value); p /= 2;) t[p] = f(t[2*p], t[2*p+1]);
}
T query(ll l, ll r) { // fold f on interval [l, r)
T resl=id, resr=id;
for (l += n, r += n; l < r; l /= 2, r /= 2) {
if (l&1) resl = f(resl, t[l++]);
if (r&1) resr = f(t[--r], resr);
}
return f(resl, resr);
}
}
void init(int N, std::vector<int> H) {
n = N;
F(i, 0, n) h[i] = H[i];
F(i, 0, n) seg::init(i, H[i]);
}
int max_towers(int L, int R, int D) {
// F(i, 0, 2*NN) seg::t[i].V = -1;
vl dp(n+1, -1);
ll res = 0;
F(i, L, R+1) {
ll ans = 1;
{
for (ll cur = i-1; cur >= L; cur--) if (h[cur] >= D + h[i]) ans = max(ans, dp[cur] + 1);
// ll l = L, r = i+1;
// while (l+1<r) {
// ll m = (l+r)/2;
// if (seg::query(m - 1, i).K >= D + h[i]) l = m;
// else r = m;
// }
// ans = max(ans, seg::query(l, i).V + 1);
// cout << "Answer for " << i << ": " << seg::query(l, i).V + 1 << endl;
// cout << "Reuqested " << l << " " << i << endl;
}
{
// ll l = i, r = R+1;
// while (l+1<r) {
// ll m = (l+r)/2;
// if (seg::query(i, m+1).K >= D + h[i]) r = m;
// else l = m;
// }
// seg::modify(r, ans);
for (ll cur = i+1; cur <= R; cur++) if (h[cur] >= D + h[i]) dp[cur] = max(dp[cur], ans);
// cout << "Placement for dp " << i << ": " << r << endl;
}
res = max(res, ans);
// cout << "WTF " << i << endl;
// F(i, L, R+1) cout << dp[i] << " "; cout << endl;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4019 ms |
3984 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2524 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
2 ms |
2528 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
3 ms |
2392 KB |
Output is correct |
14 |
Correct |
2 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
6 ms |
2392 KB |
Output is correct |
17 |
Correct |
2 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
2 ms |
2392 KB |
Output is correct |
20 |
Correct |
11 ms |
2392 KB |
Output is correct |
21 |
Correct |
10 ms |
2392 KB |
Output is correct |
22 |
Correct |
10 ms |
2392 KB |
Output is correct |
23 |
Correct |
11 ms |
2392 KB |
Output is correct |
24 |
Correct |
5 ms |
2392 KB |
Output is correct |
25 |
Correct |
3 ms |
2644 KB |
Output is correct |
26 |
Correct |
3 ms |
2392 KB |
Output is correct |
27 |
Correct |
7 ms |
2392 KB |
Output is correct |
28 |
Correct |
5 ms |
2392 KB |
Output is correct |
29 |
Correct |
5 ms |
2560 KB |
Output is correct |
30 |
Correct |
4 ms |
2392 KB |
Output is correct |
31 |
Correct |
4 ms |
2392 KB |
Output is correct |
32 |
Correct |
4 ms |
2392 KB |
Output is correct |
33 |
Correct |
5 ms |
2392 KB |
Output is correct |
34 |
Correct |
3 ms |
2392 KB |
Output is correct |
35 |
Correct |
10 ms |
2556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2524 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
2 ms |
2528 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
3 ms |
2392 KB |
Output is correct |
14 |
Correct |
2 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
6 ms |
2392 KB |
Output is correct |
17 |
Correct |
2 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
2 ms |
2392 KB |
Output is correct |
20 |
Correct |
11 ms |
2392 KB |
Output is correct |
21 |
Correct |
10 ms |
2392 KB |
Output is correct |
22 |
Correct |
10 ms |
2392 KB |
Output is correct |
23 |
Correct |
11 ms |
2392 KB |
Output is correct |
24 |
Correct |
5 ms |
2392 KB |
Output is correct |
25 |
Correct |
3 ms |
2644 KB |
Output is correct |
26 |
Correct |
3 ms |
2392 KB |
Output is correct |
27 |
Correct |
7 ms |
2392 KB |
Output is correct |
28 |
Correct |
5 ms |
2392 KB |
Output is correct |
29 |
Correct |
5 ms |
2560 KB |
Output is correct |
30 |
Correct |
4 ms |
2392 KB |
Output is correct |
31 |
Correct |
4 ms |
2392 KB |
Output is correct |
32 |
Correct |
4 ms |
2392 KB |
Output is correct |
33 |
Correct |
5 ms |
2392 KB |
Output is correct |
34 |
Correct |
3 ms |
2392 KB |
Output is correct |
35 |
Correct |
10 ms |
2556 KB |
Output is correct |
36 |
Correct |
1032 ms |
4452 KB |
Output is correct |
37 |
Correct |
906 ms |
5504 KB |
Output is correct |
38 |
Correct |
435 ms |
5508 KB |
Output is correct |
39 |
Correct |
478 ms |
5320 KB |
Output is correct |
40 |
Correct |
289 ms |
5512 KB |
Output is correct |
41 |
Execution timed out |
4034 ms |
5312 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4051 ms |
5312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4034 ms |
3092 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
3 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2524 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2392 KB |
Output is correct |
6 |
Correct |
2 ms |
2528 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
3 ms |
2392 KB |
Output is correct |
14 |
Correct |
2 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
6 ms |
2392 KB |
Output is correct |
17 |
Correct |
2 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
2 ms |
2392 KB |
Output is correct |
20 |
Correct |
11 ms |
2392 KB |
Output is correct |
21 |
Correct |
10 ms |
2392 KB |
Output is correct |
22 |
Correct |
10 ms |
2392 KB |
Output is correct |
23 |
Correct |
11 ms |
2392 KB |
Output is correct |
24 |
Correct |
5 ms |
2392 KB |
Output is correct |
25 |
Correct |
3 ms |
2644 KB |
Output is correct |
26 |
Correct |
3 ms |
2392 KB |
Output is correct |
27 |
Correct |
7 ms |
2392 KB |
Output is correct |
28 |
Correct |
5 ms |
2392 KB |
Output is correct |
29 |
Correct |
5 ms |
2560 KB |
Output is correct |
30 |
Correct |
4 ms |
2392 KB |
Output is correct |
31 |
Correct |
4 ms |
2392 KB |
Output is correct |
32 |
Correct |
4 ms |
2392 KB |
Output is correct |
33 |
Correct |
5 ms |
2392 KB |
Output is correct |
34 |
Correct |
3 ms |
2392 KB |
Output is correct |
35 |
Correct |
10 ms |
2556 KB |
Output is correct |
36 |
Correct |
1032 ms |
4452 KB |
Output is correct |
37 |
Correct |
906 ms |
5504 KB |
Output is correct |
38 |
Correct |
435 ms |
5508 KB |
Output is correct |
39 |
Correct |
478 ms |
5320 KB |
Output is correct |
40 |
Correct |
289 ms |
5512 KB |
Output is correct |
41 |
Execution timed out |
4034 ms |
5312 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4019 ms |
3984 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |