제출 #824277

#제출 시각아이디문제언어결과실행 시간메모리
824277Dec0DeddGlobal Warming (CEOI18_glo)C++14
0 / 100
245 ms29172 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") const int N = 2e5+10; const int INF = 1e9+10; struct segtree { vector<int> t; int sz; void init(int k) { sz=k+1; t.resize(2*sz); } void upd(int p, int val) { t[p+sz]=max(t[p+sz], val); for (; p>1; p>>=1) t[p>>1]=max(t[p], t[p^1]); } int que(int l, int r) { int res=0; for (l+=sz, r+=sz; l<r; l>>=1, r>>=1) { if (l&1) res=max(res, t[l++]); if (r&1) res=max(res, t[--r]); } return res; } }; int a[N], n, x, pre[N], suf[N]; unordered_map<int, int> sc; int lis() { vector<int> dp(n+1, INF); dp[0]=-INF; for (int i=1; i<=n; ++i) { int l=upper_bound(dp.begin(), dp.end(), a[i])-dp.begin(); if (dp[l-1] < a[i] && a[i] < dp[l]) dp[l]=a[i]; } int res=0; for (int i=1; i<=n; ++i) { if (dp[i] < INF) res=i; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin>>n>>x; set<int> st; for (int i=1; i<=n; ++i) { cin>>a[i]; st.insert(a[i]), st.insert(a[i]+x); } int i=1; for (auto u : st) sc[u]=i++; segtree tr2; tr2.init(2*n+10); for (int i=n; i>=1; --i) { suf[i]=tr2.que(sc[a[i]]+1, 2*n+1)+1; tr2.upd(sc[a[i]], suf[i]); } /* cout<<"pre: "; for (int i=1; i<=n; ++i) cout<<pre[i]<<" "; cout<<"\n"; cout<<"suf: "; for (int i=1; i<=n; ++i) cout<<suf[i]<<" "; cout<<"\n"; */ int ans=0; segtree tr; tr.init(2*n+1); for (int i=1; i+1<=n; ++i) { pre[i]=tr.que(1, sc[a[i]])+1; tr.upd(sc[a[i]], pre[i]); ans=max(ans, tr.que(1, sc[a[i+1]+x])+suf[i+1]); } cout<<ans<<"\n"; }
#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...