이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
int32_t main() {
cin >> N;
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
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(curvals.upper_bound(v[run[0].second+1]) != curvals.lower_bound(v[a])) 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});
curvals.insert(v[a]);
//cout << dp[a] << '\n';
}
cout << dp[N-1];
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |