#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ui unsigned int
#define ld long double
#define buster ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
buster;
ll tt = 1;
//cin >> tt;
while(tt--)
{
ll n;
cin >> n;
ll a[n + 1];
for(ll i = 1; i <= n; i++)
{
cin >> a[ i ];
}
set <ll> st;
st.insert(1000000000);
ll cnt = 1000000000;
ll ans = 1;
for(ll i = 2; i <= n; i++)
{
if(a[ i ] == a[i - 1])
{
continue;
}
auto it = st.lower_bound(a[ i ]);
if(a[ i ] < a[i - 1] || cnt != *it)
{
ans++;
cnt = *st.upper_bound(a[ i ]);
}
st.insert(a[ i ]);
}
cout << ans;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |