제출 #835159

#제출 시각아이디문제언어결과실행 시간메모리
835159dungzGlobal Warming (CEOI18_glo)C++17
37 / 100
1010 ms25280 KiB
#pragma GCC optimize ("O2") #include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define endl '\n' #define task "task" #define task "task" #define prll pair<ll,ll> #define pb push_back #define ld long double #define int ll const ll MIN=-1e18,MAX=1e18,MOD=1e9+7; map<int,int> danh; int tree[800005],a[200005],f[200005],f2[200005]; void update(int node,int l,int r,int u,int v) { if(l>u or r<u) return; if(l==r) { tree[node]=max(tree[node],v); return; } int m=(l+r)/2; update(node*2,l,m,u,v); update(node*2+1,m+1,r,u,v); tree[node]=max(tree[node*2],tree[node*2+1]); } int get(int node,int l,int r,int u,int v) { if(l>v or r<u) return 0; if(l>=u and r<=v) return tree[node]; int m=(l+r)/2; return max(get(node*2,l,m,u,v),get(node*2+1,m+1,r,u,v)); } vector<int> lst; signed main(){ // #ifndef ONLINE_JUDGE // freopen (task".inp", "r", stdin); // freopen (task".out", "w", stdout); // #endif ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n,k; cin>>n>>k; for(int i=1;i<=n;i++) { cin>>a[i]; lst.push_back(a[i]); } sort(lst.begin(),lst.end()); int d=0,ans=0; for(auto i:lst) { if(!danh[i]) { danh[i]=++d; } } // for(auto i:lst) // { // cout<<i<<" "; // } // cout<<endl; for(int i=1;i<=n;i++) { f[i]=get(1,1,n,1,danh[a[i]]-1)+1; update(1,1,n,danh[a[i]],f[i]); ans=max(ans,f[i]); // cout<<f[i]<<" "; } // cout<<endl; for(int i=1;i<=4*n;i++) tree[i]=0; for(int i=n;i>=1;i--) { f2[i]=get(1,1,n,danh[a[i]]+1,n)+1; update(1,1,n,danh[a[i]],f2[i]); // cout<<f2[i]<<" "; } // cout<<endl; for(int i=1;i<=4*n;i++) tree[i]=0; for(int i=1;i<=n;i++) { int idx=upper_bound(lst.begin(),lst.end(),a[i]+k-1)-lst.begin()-1; ans=max(ans,get(1,1,n,1,danh[lst[idx]])+f2[i]); // cout<<get(1,1,n,1,danh[lst[idx]])<<" "; update(1,1,n,danh[a[i]],f[i]); } // cout<<endl; for(int i=1;i<=4*n;i++) tree[i]=0; for(int i=n;i>=1;i--) { int idx=upper_bound(lst.begin(),lst.end(),a[i]-k)-lst.begin(); // cout<<idx<<endl; ans=max(ans,get(1,1,n,danh[lst[idx]],n)+f[i]); // cout<<ans<<" "; update(1,1,n,danh[a[i]],f2[i]); } cout<<ans; } /* */
#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...