QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#142384#1363. Bitonic OrderingA3bat_team_f_Masr#WA 4ms13724kbC++142.5kb2023-08-19 01:09:442023-08-19 01:09:45

Judging History

你现在查看的是最新测评结果

  • [2023-08-19 01:09:45]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:13724kb
  • [2023-08-19 01:09:44]
  • 提交

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);
        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);
        update(1, 1, mx, a[i], 1);
    }
    for (int i = 0; i <= n; i++)
    {
        ans = min(ans, pre[i] + suf[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: 4ms
memory: 13724kb

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'