#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MAX_N = 1e6+2;
ll a[MAX_N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin>>n;
for(ll i=0; i<n; i++)
{
cin>>a[i];
}
multiset<ll> s;
s.insert(a[0]);
for(ll i=1; i<n; i++)
{
if(a[i] >= a[i-1])
{
s.insert(a[i]);
}
else break;
}
ll idx = s.size();
ll ans = 1;
while(idx < n)
{
vector<ll> cur;
set<ll>::iterator first_lower_bound = s.lower_bound(a[idx]);
cur.push_back(a[idx]);
idx++;
ans++;
while(idx < n)
{
if(a[idx] < a[idx-1]) break;
set<ll>::iterator tmp = s.lower_bound(a[idx]);
if(tmp != first_lower_bound)
{
break;
}
cur.push_back(a[idx]);
idx++;
}
for(auto x: cur) s.insert(x);
// for(auto x: cur)
// {
// cout<<x<<" ";
// }
// cout<<endl;
}
cout<<ans<<endl;
}
/**
6
3 6 4 5 1 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |