10pts 求调,马蜂良好
查看原帖
10pts 求调,马蜂良好
974277
水星湖psgqwq楼主2024/3/14 22:47
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int p = 1e8 - 3;
int n, a[100005], b[100005], la[100005], lb[100005], c[100005], ans, t[100005];

void add(int x)
{
    while (x <= n)
    {
        t[x] = t[x] + 1;
        x += x & -x;
    }
}

int query(int x)
{
    int res = 0;
    while (x)
    {
        res = res + t[x];
        x -= x & -x;
    }
    return res; 
}

signed main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i], la[i] = i;
    for (int i = 1; i <= n; i++)
        cin >> b[i], lb[i] = i;
    sort(la + 1, la + n + 1, [](int x, int y) { return a[x] < a[y]; });
    sort(lb + 1, lb + n + 1, [](int x, int y) { return b[x] < b[y]; });
    for (int i = 1; i <= n; i++)
        c[la[i]] = i;
    for (int i = 1; i <= n; i++)
        b[i] = c[lb[i]];
    for (int i = n; i; i--)
    {
        ans += query(b[i] - 1);
        add(b[i]);
    }
    cout << ans % p<< endl;
    return 0;
}
2024/3/14 22:47
加载中...