QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#59712 | #1363. Bitonic Ordering | triplem5ds | WA | 2ms | 3632kb | C++14 | 1.4kb | 2022-10-31 21:44:09 | 2022-10-31 21:44:12 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define ll long long
#define ld double
using namespace std;
const int N = 2e5 + 5, lg = 19, mod = 998244353;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k): returns the number of elements in the set strictly less than k
// find_by_order(k): returns an iterator to the k-th element (zero-based) in the set
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
vector<ll> pref(n + 1, 0), suff(n + 2, 0);
ordered_set st;
for(int i = 1; i <= n; i++) {
pref[i] = pref[i - 1] + st.order_of_key(-a[i]);
st.insert(-a[i]);
}
st.clear();
for(int i = n; i >= 1; i--) {
suff[i] = suff[i + 1] + st.order_of_key(-a[i]-1);
st.insert(-a[i]);
}
ll ans = min(pref[n], suff[1]);
// cout << pref[n] << ' ' << suff[1] << ' ';
for(int i = 1; i + 1 <= n; i++) {
// cout << i << ' ' << pref[i] << ' ' << suff[i + 1] << ' ' << pref[i] + suff[i + 1] << '\n';
ans = min(ans, pref[i] + suff[i + 1]);
}
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3632kb
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'