#include <bits/stdc++.h>
using namespace std;
const int NM = 1e6, inf = 1e9+7;
int N, a[NM+5], ans = 0;
set <int> S;
set <int>::iterator it;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int i = 1; i <= N; i++) cin >> a[i];
for (int i = 1; i <= N; i++){
int j = i, l, r;
if (S.empty()) l = -inf, r = +inf;
else if (a[i] < *S.begin()) l = -inf, r = *S.begin();
else if (a[i] >= *(--S.end())) l = *(--S.end()), r = +inf;
else{
it = S.upper_bound(a[i]);
r = *it;
it--;
l = *it;
}
while (j <= N && a[j] >= l && a[j] <= r){
S.insert(a[j]);
l = a[j];
j++;
}
ans++;
i = j;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |