QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#331341 | #1363. Bitonic Ordering | weilaifuture# | WA | 0ms | 5740kb | C++14 | 1.8kb | 2024-02-18 05:38:36 | 2024-02-18 05:38:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
int m1, m, tree[1200005], fr[300005], ba[300005];
int n, x;
vector <pair <int, int> > v;
bool cmp (pair <int, int> a, pair <int, int> b) {
return a.first > b.first;
}
void update(int idx, int ki, int ka, int x) {
//cout << ki << " " << ka << " " << idx << endl;
if (ki > ka || ki > x || ka < x) return;
if (ki == ka && ki == x) {
tree[idx]++;
return;
}
update(idx * 2, ki, (ki + ka)/2, x);
update(idx * 2 + 1, (ki + ka)/2 + 1, ka, x);
tree[idx] = tree[idx * 2] + tree[idx * 2 + 1];
}
int query(int idx, int ki, int ka, int qki, int qka) {
if (ki > ka || ki > qka || qki > ka) return 0;
if (qki <= ki && ka <= qka) return tree[idx];
int a = query(idx * 2, ki, (ki + ka)/2, qki, qka);
int b = query(idx * 2 + 1, (ki + ka)/2 + 1, ka, qki, qka);
return a + b;
}
signed main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
v.push_back({x, i});
if (x > m1) {
m1 = x;
m = i;
}
} sort(v.begin(), v.end(), cmp);
for (auto g:v) {
int a = g.first;
int idx = g.second;
fr[idx] = query(1, 1, n, 1, idx - 1);
ba[idx] = query(1, 1, n, idx + 1, n);
if (idx == m) continue;
update(1, 1, n, idx);
}
for (int i = 1; i <= n; i++) {
fr[i] += fr[i - 1];
}
for (int i = n; i > 0; i--) {
ba[i] += ba[i + 1];
}
int ans = 1e18;
for (int i = 0; i <= n; i++) {
int tmp = fr[i] + ba[i + 1] + abs(i - m);
//cout << fr[i] << " " << ba[i + 1] << endl;
ans = min(tmp, ans);
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5740kb
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'