Submission #710173

#TimeUsernameProblemLanguageResultExecution timeMemory
710173zyq_Money (IZhO17_money)C++17
0 / 100
104 ms125544 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int N; int dp[1000010]; deque<pair<int, int> > run; int inp; vector<int> v; set<int> curvals; int maxbefore[1000010]; struct node{ //range min int s, e, M; int val; node *l, *r; node(int S, int E){ s = S; e = E; M = (S + E)/2; val = INT_MAX; if(s == e) return; l = new node(S, M); r = new node(M+1, E); } void update(int x, int k){ if(s == e){ val = min(val, k); return; } if(x <= M) l->update(x, k); else r->update(x, k); } int query(int x, int y){ if(x <= s && e <= y){ return val; } if(y <= M) return l->query(x, y); else if(x > M) return r->query(x, y); else return min(l->query(x, M), r->query(M+1, y)); } } *root; int32_t main() { cin >> N; root = new node(1, 1000010); for(int a=0; a<N; a++){ dp[a] = 0; cin >> inp; v.push_back(inp); if(a == 0){ maxbefore[a] = 0; } else{ if(v[a-1] <= v[a]){ maxbefore[a] = maxbefore[a-1]; } else{ maxbefore[a] = a; } } } run.push_back({0, -1}); for(int a=0; a<N; a++){ //cout << "hi"; //start the dp //eradicate imposs queue //cout << run.size(); //cout << maxbefore[a]; while(!run.empty()){ if(run[0].second < maxbefore[a]-1) run.pop_front(); else break; } //cout << "ok"; //cout << run.size(); //cout << run.back().second; while(!run.empty()){ //check if current thing fits somewhere //range from v[run[0].first] to v[a] //cout << (curvals.upper_bound(v[run[0].second]) == curvals.end()); //cout << (curvals.lower_bound(v[a]) == curvals.end()); if(v[run[0].second+1] != v[a] && v[run[0].second+1]+1 != v[a] && root->query(v[run[0].second+1]+1, v[a]-1) < run[0].second+1) run.pop_front(); else break; } //then start to do //cout << "again"; // cout << run.size(); dp[a] = run[0].first + 1; while(!run.empty()){ if(run.back().first > dp[a]){ run.pop_back(); } else break; } //cout << "sup"; run.push_back({dp[a], a}); root->update(v[a], a); //cout << dp[a] << '\n'; } cout << dp[N-1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...