Submission #564101

#TimeUsernameProblemLanguageResultExecution timeMemory
564101OttoTheDinoFinancial Report (JOI21_financial)C++98
0 / 100
143 ms22080 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,s,e) for (int i = s; i <= e; ++i) #define rrep(i,s,e) for (int i = s; i >= e; --i) #define pb push_back #define pf push_front #define fi first #define se second #define all(a) a.begin(), a.end() #define len(a) (int)a.size() typedef long long ll; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; map<int,vi> mp; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, d; cin >> n >> d; int a[n+1] = {}; rep (i,1,n) { cin >> a[i]; mp[a[i]].pb(i); } set<ii> st; vi rem[n+d+2]; for (pair<int,vi> p : mp) { int val = p.fi; vi ids = p.se; rrep (j,len(ids)-1,0) { int x = ids[j]; auto it = st.lower_bound({x+1,0}); int s = x, e = x; if (it!=st.end() && (*it).fi-x<=d) { e = (*it).se; it = st.erase(it); } if (it!=st.begin() && x-(*--it).se<=d) { s = (*it).fi; e = max(e, (*it).se); st.erase(it); } st.insert({s,e}); rem[e+d+1].pb(val); } } st.clear(); st.insert({0,0}); rep (i,1,n) { for (int r : rem[i]) { auto it = st.lower_bound({r,0}); if (it!=st.end() && (*it).fi==r) st.erase(it); } auto it = st.lower_bound({a[i],0}); if (it==st.end()) st.insert({a[i], (*--it).se+1}); else if ((*it).fi!=a[i]) { int x = (*--it).se+1; if ((*++it).se == x) st.erase(it); st.insert({a[i], x}); } } cout << (*st.rbegin()).se << "\n"; 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...