Submission #539172

#TimeUsernameProblemLanguageResultExecution timeMemory
539172UncoolAnonGlobal Warming (CEOI18_glo)C++17
100 / 100
130 ms7756 KiB
#include <bits/stdc++.h> using namespace std; const int mx=1e6+5; vector<int> tw(mx,1e9); int query(int i,int l,int r,int v){ if(l==r) return l; if(tw[i*2+1]<v) return query(i*2+1,(l+r)/2+1,r,v); return query(i*2,l,(r+l)/2,v); } void update(int i,int l,int r,int target,int v){ if(target<l||r<target) return; if(l==r) tw[i]=min(tw[i],v); else{ update(i*2,l,(r+l)/2,target,v); update(i*2+1,(r+l)/2+1,r,target,v); tw[i]=min(tw[i*2],tw[i*2+1]); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); int n,x; cin>>n>>x; vector<int> a(n); for(int&x:a)cin>>x; vector<int> on(n+1,2e9+1); on[0]=0; update(1,0,n,0,0); int answer=0; for(int i=0;i<n;i++){ int l=0,r=n+1; while(r-l!=1){int md=(r+l)/2; if(on[md]<a[i]) l=md;else r=md;} int one=l+1; l=0,r=n+1; while(r-l!=1){int md=(r+l)/2; if(on[md]-x<a[i]) l=md; else r=md;} int two=l+1; l=query(1,0,n,a[i]); on[one]=min(a[i],on[one]); answer=max({answer,l+1,two,one}); update(1,0,n,max({l+1,two,one}),a[i]); } cout<<answer; 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...