이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 x <= *it){
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |