#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 1e6 + 5;
int N;
int A[NMAX];
set <int> S;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N;
for (int i = 1; i <= N; ++ i )
cin >> A[i];
int ans = 0;
for (int i = 1; i <= N; ++ i ) {
++ ans;
int j = i;
if (S.empty()) {
for (; j <= N && A[j+1] >= A[j]; ++ j );
for (int k = i; k <= j; ++ k )
S.insert(A[k]);
i = j;
continue;
}
auto it = S.upper_bound(A[i]);
if (it == S.end()) {
for (; j <= N && A[j+1] >= A[j]; ++ j );
for (int k = i; k <= j; ++ k )
S.insert(A[k]);
i = j;
continue;
}
for (; j <= N && A[j+1] >= A[j] && A[j+1] < *it; ++ j );
for (int k = i; k <= j; ++ k )
S.insert(A[k]);
i = j;
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |