Submission #657377

#TimeUsernameProblemLanguageResultExecution timeMemory
657377teeslaGlobal Warming (CEOI18_glo)C++14
0 / 100
111 ms3792 KiB
#include <bits/stdc++.h> using namespace std; const int maxn=2*1e5+10; int v[maxn],lis[maxn],lds[maxn],ida[maxn],volta[maxn]; int busca(int i, int f, int x){ int res=1; while(i<=f){ int mid=(i+f)/2; if(lis[mid]>=x or lis[mid]==0)f=mid-1; else{ i=mid+1; res=mid+1; } } return res; } int busca2(int i, int f, int x){ int res=1; while(i<=f){ int mid=(i+f)/2; if(lds[mid]<=x) f=mid-1; else{ i=mid+1; res=mid+1; } } return res; } int main(){ int n,x; cin >> n>> x; for(int i=1; i<=n; i++)cin >> v[i]; for(int i=1; i<=n; i++){//v[i] faz parte da lis final int j= busca(1,n,v[i]);// pos do menor maior que v[i] lis[j]=v[i]; ida[i]=j; } for(int i=n; i>=1; i--){ int j=busca2(1,n,v[i]-x);// pos do menor >v[i]-x (tam lds) volta[j]=j; int k=busca2(1,n,v[i]);//lds normal para colocar na lista lds[k]=v[i]; } int res=0; for(int i=1; i<=n; i++){ res=max(res,ida[i]+volta[i]); } cout << res<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...