This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i = a; i < b; i++)
const int N = 1e6 + 6;
int n, a[N], dp[N];
set <int> s;
int main(){
cin >> n;
f(i,1,n+1) cin >> a[i];
a[n+1] = N;
int id = 0;
s.insert(0);
f(i,1,n+1){
dp[i] = 1;
if(a[i] > a[i+1]) break;
}
while(id <= n){
while(id <= n and a[id] <= a[id+1]) s.insert(a[id]), id++;
s.insert(a[id++]);
f(i,id,n+1){
s.insert(N);
auto it = s.lower_bound(a[i]);
it = prev(it);
s.erase(N);
int x = *it, j;
j = lower_bound(a+id,a+i+1,x) - a;
dp[i] = dp[j-1] + 1;
if(a[i] > a[i+1]) break;
}
}
cout << dp[n] << "\n";
return 0;
}
# | 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... |