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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, arr[303030];
ll lt[303030], rt[303030];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> arr[i];
vector<int> v;
for (int i = 1; i <= n; i++) {
lt[i] = lt[i - 1] + (v.end() - upper_bound(v.begin(), v.end(), arr[i]));
v.push_back(arr[i]);
sort(v.begin(), v.end());
}
v.clear();
for (int i = n; i >= 1; i--) {
rt[i] = rt[i + 1] + (v.end() - upper_bound(v.begin(), v.end(), arr[i]));
v.push_back(arr[i]);
sort(v.begin(), v.end());
}
ll ans = 1e18;
for (int i = 0; i <= n; i++) ans = min(ans, lt[i] + rt[i + 1]);
cout << ans << "\n";
return 0;
}
# | 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... |