QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#394795 | #1363. Bitonic Ordering | MahmoudBassem | WA | 1ms | 3860kb | C++17 | 1.9kb | 2024-04-20 19:42:23 | 2024-04-20 19:42:24 |
Judging History
answer
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
// less_equal here isn't related to order_of_key, but to how elements are stored
// swapping here works like this : ors1.swap(ors2);
// NOTE : default order is ascending with no repetition.
template<typename K, typename V, typename Comp = less<K>>
using order_statistic_map = tree<K, V, Comp, rb_tree_tag, tree_order_statistics_node_update>;
template<typename K, typename Comp = less<K>>
using order_statistic_set = order_statistic_map<K, null_type, Comp>;
#define int long long
#define ld long double
#define el '\n'
#define fi first
#define se second
#define Nine_seconds ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int INF = 1e17;
void run_case(int tc) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> pref;
vector<int> suf;
order_statistic_set<int> ors;
for (int i = 0; i < n; i++) {
pref.emplace_back(ors.size() - ors.order_of_key(a[i]));
if (i) pref[i] += pref[i - 1];
ors.insert(a[i]);
// cout << pref.back() << el;
}
reverse(a.begin(), a.end());
ors.clear();
for (int i = 0; i < n; i++) {
suf.emplace_back(ors.size() - ors.order_of_key(a[i]));
if (i) suf[i] += suf[i - 1];
ors.insert(a[i]);
// cout << suf.back() << el;
}
//reverse(suf.begin(), suf.end());
int ans = INF;
for (int i = 0; i < n - 1; i++) {
ans = min(ans, pref[i] + suf[n - i - 2]);
}
ans = min(ans, pref[n - 1]);
ans = min(ans, suf[n - 1]);
cout << ans << el;
}
int32_t main() {
Nine_seconds /*Turn Off for Interactive Problems*/
int _t = 1;
//cin >> _t;
for (int i = 1; i <= _t; i++) {
run_case(i);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3860kb
input:
13 39 40 32 100 13 16 15 28 27 26 25 24 23
output:
15
result:
wrong answer 1st lines differ - expected: '14', found: '15'