#include "towers.h"
#include<bits/stdc++.h>
#define vi vector<int>
#define pb push_back
#define f0r(i,n) for(int i = 0; i<n; i++)
#define FOR(i, k, n) for(int i = k; i<n; i++)
using namespace std;
int mxd = -1;
int mx = 0;
vi v;
const int mxn = 1e5 + 5;
vi tree(mxn * 4);
int n;
void update(int k, int x){
k += n;
tree[k] = x;
for(k /=2; k>=1; k/=2){
tree[k] = max(tree[k*2], tree[k*2+1]);
}
}
int quer(int l, int r){
if(l >r)return 0;
l += n; r += n;
int ret = 0;
while(l <= r){
if(l % 2 == 1)ret = max(ret, tree[l++]);
if(r % 2 == 0)ret = max(ret, tree[r--]);
r /=2; l /=2;
}
return ret;
}
void init(int N, std::vector<int> v) {
n = N;
::v = v;
f0r(i, N){
if(v[i] > mx){
mx = v[i];
mxd = i;
}
}
f0r(i, N){
update(i, v[i]);
}
}
int max_towers(int l, int r, int d) {
vi v;
FOR(i, l, r+1){
v.pb(::v[i]);
}
int n = r - l + 1;
vector<vi> dp(n, vi(n+1));
dp[0][0] = 1;
vi mx(n);
mx[0] = 1;
FOR(i, 1, n){
dp[i][0] = 1;
FOR(j, 1, i+1){
int maxx = quer(j, i - 1) - d;
if(v[j-1] <= maxx && v[i] <= maxx)dp[i][j] = mx[j-1] + 1;
}
f0r(j, n+1)mx[i] = max(mx[i], dp[i][j]);
}
int ans = 0;
f0r(i,n)f0r(j, n+1)ans = max(ans, dp[i][j]);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |