제출 #781720

#제출 시각아이디문제언어결과실행 시간메모리
781720joelgun14Global Warming (CEOI18_glo)C++17
0 / 100
194 ms9356 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], 0)) != s.begin()) { pair<int, int> pr = *--s.lb(mp(t[i], 0)); if(pr.se <= pref[i]) s.erase(s.find(pr)); else break; } 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...