#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 + 1;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |