This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100, K = 20;
bool case2 = 1;
int k, dp[N][2], n;
vector<int> A;
void init(int NN, std::vector<int> a){
n = NN;
if(n > 2000) case2 = 0;
k = max_element(a.begin(), a.end()) - a.begin();
A = a;
}
int max_towers(int L, int R, int D){
if(!case2){
if(R <= k || L >= k) return 1;
if(A[L] <= A[k] - D && A[R] <= A[k] - D) return 2;
return 1;
}
for(int i = 0; i < n; ++i) dp[i][0] = 1, dp[i][1] = 0;
vector<int> left(n, -1), right(n, -1);
deque<pair<int, int>> q;
for(int i = L; i <= R; ++i){
while(!q.empty() && q.front().first < A[i] + D){
q.pop_front();
}
if(!q.empty()) left[i] = q.front().second;
q.push_front({A[i], i});
}
q.clear();
for(int i = R; i >= L; --i){
while(!q.empty() && q.front().first < A[i] + D){
q.pop_front();
}
if(!q.empty()) right[i] = q.front().second;
q.push_front({A[i], i});
}
for(int i = L; i <= R; ++i){
if(left[i] != -1) dp[i][0] = dp[left[i]][1] + 1;
if(right[i] != -1) dp[right[i]][1] = max(dp[right[i]][1], dp[i][0]);
}
int ans = 0;
for(int i = L; i <= R; ++i) ans=max(ans,dp[i][0]);
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... |