#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int ans = 0, n, x, prevx = -1; cin >> n;
int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i];
multiset <int> ms;
set <int> s;
bool flag = false;
for (int i = 0; i < n; i++){
x = arr[i];
ms.insert(arr[i]);
s.insert(arr[i]);
if (!i){
ans += 1;
flag = true;
}
else if (flag){
if (prevx > x){
ans += 1;
flag = true;
}
else if (prevx < x){
auto it = s.find(prevx);
it++;
if (it != s.end() and *it <= x){
flag = false;
}
else ans += 1, flag = true;
}
}
else{
if (prevx > x){
ans += 1;
flag = true;
}
else if (prevx < x){
auto it = s.find(prevx);
it++;
if (it != s.end() and x <= *it and ms.count(prevx) == 1){
//cerr << prevx << ' ' << *it << ' ' << x << '\n';
flag = false;
}
else ans += 1, flag = true;
}
}
//cerr << ans << '\n';
//cerr << ans << ' ' << *prev << ' ' << *cur << '\n';
prevx = x;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |