Submission #781730

#TimeUsernameProblemLanguageResultExecution timeMemory
781730joelgun14Global Warming (CEOI18_glo)C++17
0 / 100
178 ms3724 KiB
#include <bits/stdc++.h> #define endl "\n" #define mp make_pair #define fi first #define se second #define lb lower_bound using namespace std; int main() { int n, x; cin >> n >> x; int t[n + 1]; for(int i = 1; i <= n; ++i) { cin >> t[i]; } // find prefix lis/suffix lis, nanti cari yg max di mana // suffix lis -> lds dr belakang // prefix lis -> lis dr depan int pref[n + 1], suff[n + 1]; set<int> lis, lds; for(int i = 1; i <= n; ++i) { if(lis.lower_bound(t[i]) != lis.end()) { lis.erase(lis.lower_bound(t[i])); lis.insert(t[i]); } else { lis.insert(t[i]); } pref[i] = lis.size(); } for(int i = n; i >= 1; --i) { if(lds.lower_bound(-t[i]) != lds.end()) { lds.erase(lds.lb(-t[i])); lds.insert(-t[i]); } else lds.insert(-t[i]); suff[i] = lds.size(); } // fi -> t // se -> lis set<pair<int, int>> s; int ret = pref[n]; for(int i = n; i >= 1; --i) { if(s.lb(mp(t[i] - x + 1, 0)) != s.end()) { //cout << pref[i] << " " << (*s.lb(mp(t[i] - x + 1, 0))).se << endl; //cout << "DEB " << i << " " << t[i] << " " << (*s.lb(mp(t[i] - x + 1, 0))).fi << " " << (*s.lb(mp(t[i] - x + 1, 0))).se << endl; ret = max(ret, (*s.lb(mp(t[i] - x + 1, 0))).se + pref[i]); } while(s.lb(mp(t[i], 1e9)) != s.begin()) { pair<int, int> pr = *--s.lb(mp(t[i], 0)); if(pr.se <= pref[i]) s.erase(s.find(pr)); else break; } if(s.lb(mp(t[i], 0)) != s.end() && (*s.lb(mp(t[i], 0))).se >= pref[i]) { } else s.insert(mp(t[i], suff[i])); } cout << ret << endl; }
#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...