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 <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
const int N = 1e6 + 2;
int n;
int a[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = n;
int cl = 1;
for (int i = 1; i < n; i++) {
if (a[i] > a[i + 1]) {
ans -= i - cl;
cl = i + 1;
continue;
}
bool f = true;
for (int j = 1; j < cl; j++) {
if (a[j] > a[cl] && a[j] < a[i + 1]) {
f = false;
break;
}
}
if (!f) {
ans -= (i - cl);
cl = i + 1;
}
}
ans -= (n - cl);
cout << ans << endl;
return 0;
}
/*
6
3 6 4 5 1 2
6
1 2 2 3 4 5
*/
# | 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... |