This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int, int>
const int N = 1e6 + 2;
int n;
int a[N];
vector<int> vec;
bool find(int cl, int cr) {
for (int i = 0; i < vec.size(); i++) {
}
return 0;
}
bool check(int l, int r, int cl, int cr) {
int x = upper_bound(a + l, a + r, a[cl]) - a - l;
int y = lower_bound(a + l, a + r, a[cr]) - a - l;
if (x < (r - l) && x < y)
return false;
else
return true;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = n;
int cl = 1;
vec.push_back(0);
for (int i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) {
ans -= i - cl;
cl = i + 1;
//sort(a + vec.back(), a + cl);
sort(a, a + cl);
continue;
}
if(!check(0, cl, cl, i + 1)) {
ans -= i - cl;
cl = i + 1;
sort(a, a + cl);
}
}
ans -= (n - cl);
cout << ans << endl;
return 0;
}
/*
6
3 6 4 5 1 2
6
1 2 2 3 4 5
4
4 1 4 5
*/
Compilation message (stderr)
money.cpp: In function 'bool find(int, int)':
money.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int i = 0; i < vec.size(); i++) {
| ~~^~~~~~~~~~~~
# | 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... |