#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 = 0; i < n; i++) {
cin >> a[i];
}
int ans = n;
int cl = 1;
for (int i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) {
ans -= i - cl;
cl = i + 1;
sort(a, a + cl);
continue;
}
int x = upper_bound(a, a + cl, a[cl]) - a;
int y = lower_bound(a, a + cl, a[i + 1]) - a;
if(x != y) {
ans -= (i - cl);
cl = i + 1;
sort(a, a + cl);
}
}
ans -= (n - cl);
cout << ans << endl;
return 0;
}
/*
6
3 6 4 5 1 2
6
1 2 2 3 4 5
4
4 1 4 5
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |