#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0) -> ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector<int> a(n);
for(int i=0;i<n;i++) cin >> a[i];
set<int> s;
int ans = 0, i = 0;
while(i < n)
{
s.insert(a[i]);
if(a[i + 1] < a[i]) break;
i++;
}
for(;i<n;i++)
{
auto x = s.upper_bound(a[i-1]);
ans++;
int y;
if(x == s.end())
{
y = a[i];
while(i < n)
{
s.insert(a[i]);
if(a[i + 1] < a[i]) break;
i++;
}
}
else if(a[i] <= *x)
{
y = *x;
while(i < n && a[i] <= y)
{
s.insert(a[i]);
if(a[i + 1] < a[i]) break;
i++;
}
}
else // a[i] > the el after prev element
{
s.insert(a[i]);
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 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 |
1 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 |
1 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 |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |