0分RE,样例已过,求dalao指导,求调

P1908 逆序对

wuxikai @ 2024-10-09 12:37:09

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e5 + 7;
long long n, q;
long long c[N], a[N];
void update(int i, long long x)
{
    for (; i <= n; i += i & -i)
        c[i] += x;
}
long long query(int i)
{
    long long ans = 0;
    for (; i; i -= i & -i)
    {
        ans += c[i];
    }
    return ans;
}
signed main()
{
    long long ans = 0;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
        update(a[i], 1);
        long long sum = query(a[i]);
        ans += i - sum;
    }
    cout << ans;
    return 0;
}

by wangborui123 @ 2024-10-09 12:56:29

这题需要离散化吧


by wuxikai @ 2024-10-09 16:30:24

40分WA 改了离散化之后只有40pts咋办啊━┳━ ━┳━


by wuxikai @ 2024-10-09 17:02:12

100分好了现在AC了谢谢指导


|