QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142395 | #1363. Bitonic Ordering | A3bat_team_f_Masr# | WA | 0ms | 14756kb | C++14 | 2.5kb | 2023-08-19 01:33:29 | 2023-08-19 01:33:33 |
Judging History
answer
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;
#define IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define all(x) x.begin(), (x).end()
#define el '\n'
#define sz(v) (int)(v).size()
#define TC \
int tc; \
cin >> tc; \
while (tc--)
#define pi acos(-1.0)
#define oo LONG_LONG_MAX
#define yes cout << "YES" << el
#define no cout << "NO" << el
#define N (int)3e5 + 4
bool isPrime(ll n)
{
if (n == 1 || n == 0)
return false;
if (n % 2 == 0 && n != 2)
return false;
if (n == 2)
return true;
for (ll i = 3; i <= sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
bool vis[N];
int dx[] = {0, 0, 1, -1, 1, -1, -1, 1};
int dy[] = {-1, 1, 0, 0, 1, -1, 1, -1};
vector<int> adj[N];
int n, a[N], idx[N], tree[4 * N];
ll pre[N], suf[N];
void update(int me, int l, int r, int idx, int val)
{
if (l == r)
{
tree[me] = val;
return;
}
int m = (l + r) >> 1;
if (idx <= m)
update(2 * me, l, m, idx, val);
else
update(2 * me + 1, m + 1, r, idx, val);
tree[me] = tree[2 * me] + tree[2 * me + 1];
}
int sum(int me, int l, int r, int st, int en)
{
if (l > en || r < st)
return 0;
if (l >= st && r <= en)
return tree[me];
int m = (l + r) >> 1;
return sum(2 * me, l, m, st, en) + sum(2 * me + 1, m + 1, r, st, en);
}
void solve()
{
map<int, int> rev, mp;
cin >> n;
int mx = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
mp[a[i]] = i;
}
int id = 0;
for (auto x : mp)
rev[x.first] = ++id;
for (int i = 1; i <= n; i++)
{
a[i] = rev[a[i]];
idx[a[i]] = i;
if (a[i] > mx)
mx = a[i];
}
ll ans = 1e18;
for (int i = 1; i <= n; i++)
{
pre[i] = pre[i - 1];
pre[i] += sum(1, 1, mx, a[i], mx);
if(a[i]!=mx)update(1, 1, mx, a[i], 1);
}
for (int i = 1; i <= mx; i++)
update(1, 1, mx, i, 0);
for (int i = n; i >= 1; i--)
{
suf[i] = suf[i + 1];
suf[i] += sum(1, 1, mx, a[i], n);
if(a[i]!=mx)update(1, 1, mx, a[i], 1);
}
for (int i = 0; i < n; i++)
{
ans = min(ans, pre[i+1] + suf[i + 2]+abs(idx[mx]-(i+1)));
}
cout << ans;
}
int main()
{
// IO
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 14756kb
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'