QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#331394 | #1363. Bitonic Ordering | weilaifuture# | WA | 3ms | 15488kb | C++14 | 1.6kb | 2024-02-18 07:25:04 | 2024-02-18 07:25:05 |
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, tmp;
vector <pair <int, int> > v;
bool cmp (pair <int, int> a, pair <int, int> b) {
return a.first > b.first;
}
int lowbit(int x){return x&(-x);}
void update(int x, int v){
while(x<=n) tree[x]+=v,x+=lowbit(x);
}
int query(int x){
int tmp1=0;
while(x) tmp1+=tree[x], x-=lowbit(x);
return tmp1;
}
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);
memset(tree, 0, sizeof(tree));
for (auto g:v) {
int a = g.first;
int idx = g.second;
if (idx == m) continue;
fr[idx] = query(idx - 1);
ba[idx] = tmp - query(idx);
update(idx,1); tmp++;
}
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=1;i<=n+1;i++) ans = min(ans,fr[i-1]+ba[i]+abs(i-m));
/*for (int i = 1; i < m; i++) {
int tmp = fr[i - 1] + ba[i] + abs(i - m);
//cout << fr[i - 1] << " " << ba[i] << endl;
ans = min(tmp, ans);
}
ans = min(ans, fr[m - 1] + ba[m + 1]);
for (int i = m + 1; i <= n; i++) {
int tmp = fr[i] + ba[i + 1] + abs(i - m);
ans = min(tmp, ans);
}*/
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 15488kb
input:
13 39 40 32 100 13 16 15 28 27 26 25 24 23
output:
16
result:
wrong answer 1st lines differ - expected: '14', found: '16'