#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 1e6 + 3;
int n;
int a[maxn];
void read()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
}
set <int> s;
void solve()
{
int ans = 0;
for (int i = 1; i <= n; )
{
ans++;
auto it = s.lower_bound(a[i]);
bool is = false;
for (int j = i+1; j <= n; j++)
{
auto it1 = s.lower_bound(a[j]);
if (a[j] < a[j-1] || !(it == s.end() || it1 == it || it1 == next(it)))
{
for (int k = i; k < j; k++)
s.insert(a[k]);
is = true;
i = j;
break;
}
}
if (!is)
break;
}
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
}
/*
6
3 6 4 5 1 2
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |