QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#59713 | #1363. Bitonic Ordering | triplem5ds | WA | 3ms | 3568kb | C++14 | 1.4kb | 2022-10-31 21:44:43 | 2022-10-31 21:44:43 |
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]-1);
st.insert(-a[i]);
}
st.clear();
for(int i = n; i >= 1; i--) {
suff[i] = suff[i + 1] + st.order_of_key(-a[i]);
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: 100
Accepted
time: 3ms
memory: 3568kb
input:
13 39 40 32 100 13 16 15 28 27 26 25 24 23
output:
14
result:
ok single line: '14'
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3464kb
input:
4 3 2 1 10
output:
1
result:
wrong answer 1st lines differ - expected: '2', found: '1'