# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1117497 | KALARRY | Global Warming (CEOI18_glo) | C++14 | 60 ms | 7056 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.
//chockolateman
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
long long N,x,t[200005],suff[200005],dp[200005]; //suff[i] = LIC of the suff i starting with at least t[i-1] - d + 1
int main()
{
scanf("%lld%lld",&N,&x);
for(long long i = 1 ; i <= N ; i++)
scanf("%lld",&t[i]);
dp[0] = INF;
for(long long i = 1 ; i <= N ; i++)
dp[i] = - INF;
for(long long i = N ; i >= 1 ; i--)
{
long long pos = 0;
for(long long b = N ; b >= 1 ; b/=2)
while(pos + b <= N && dp[pos+b] > t[i])
pos += b;
dp[pos+1] = max(dp[pos+1],t[i]);
pos = 0;
for(long long b = N ; b >= 1 ; b/=2)
while(pos + b <= N && dp[pos+b] > t[i-1] - x)
pos += b;
suff[i] = pos;
}
long long ans = 0;
for(long long i = 1 ; i <= N ; i++)
dp[i] = INF;
dp[0] = 0;
for(long long i = 1 ; i <= N ; i++)
{
long long pos = lower_bound(dp,dp+N+1,t[i]) - dp - 1;
dp[pos+1] = min(dp[pos+1],t[i]);
ans = max(ans,pos+1 + suff[i+1]);
}
printf("%lld\n",ans);
return 0;
}
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... |