# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
953272 | AlphaMale06 | Global Warming (CEOI18_glo) | C++14 | 58 ms | 11100 KiB |
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;
#define pb push_back
const int N = 2e5+3;
vector<int> dp[N];
int ndp[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, d;
cin >> n >> d;
int a[n];
for(int i=0; i< n; i++)cin >> a[i];
dp[0].pb(2e9+1);
int mx=0;
for(int i = n-1; i>=0; i--){
if(a[i]<dp[mx].back()){
mx++;
dp[mx].pb(a[i]);
continue;
}
int l = 1, r = mx;
while(l<=r){
int s = l+r>>1;
if(dp[s].back()>=a[i])l=s+1;
else r=s-1;
}
if(dp[l].back()<=a[i])dp[l].pb(a[i]);
}
int ans=mx;
for(int i = 1; i<=n; i++)ndp[i]=1e9+i;
ndp[0]=-1e9;
int mxx=0;
for(int i=0; i < n; i++){
if(a[i]==dp[mx].back()){
dp[mx].pop_back();
if(!dp[mx].size())mx--;
}
else{
int l = 1, r = mx;
while(l<=r){
int s = l+r>>1;
if(dp[s].back()>=a[i])l=s+1;
else r=s-1;
}
if(dp[r].size() && dp[r].back()==a[i])dp[r].pop_back();
}
int l = 0, r = n;
if(a[i]-d>ndp[mxx]){
mxx++;
ndp[mxx]=a[i]-d;
}
else{
while(l<=r){
int s = l+r>>1;
if(ndp[s]>a[i]-d)r=s-1;
else l=s+1;
}
ndp[l]=min(ndp[l], a[i]-d);
}
l=1 , r=mx;
while(l<=r){
int s = l+r>>1;
if(dp[s].back()>ndp[mxx]){
ans=max(ans, mxx+s);
l=s+1;
}
else{
r=s-1;
}
}
}
cout << ans << '\n';
}
Compilation message (stderr)
# | 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... |