这能RE?
  • 板块UVA1428 Ping pong
  • 楼主BIOS
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/12/18 23:06
  • 上次更新2023/12/19 14:44:10
查看原帖
这能RE?
833124
BIOS楼主2023/12/18 23:06
#include <iostream>
using namespace std;
#define int long long
const int N = 1e5 + 5, lim = 100000;
int n, x, tr[N], tot, t, l_low[N], r_low[N], l_up[N], r_up[N], a[N];
int lowbit(int x) { return x & -x; }
int add(int x, int c)
{
    for (int i = x; i <= lim; i += lowbit(i))
        tr[i] += c;
}
int sum(int x)
{
    int res = 0;
    for (int i = x; i; i -= lowbit(i))
        res += tr[i];
    return res;
}
signed main()
{
    cin >> t;
    while (t--)
    {
        cin >> n, tot = 0;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        for (int i = 0; i <= lim; i++)
            tr[i] = 0;
        for (int i = 1; i <= n; i++)
            l_low[i] = sum(a[i]), l_up[i] = sum(lim) - sum(a[i] - 1), add(a[i], 1);
        for (int i = 0; i <= lim; i++)
            tr[i] = 0;
        for (int i = n; i; i--)
            r_low[i] = sum(a[i]), r_up[i] = sum(lim) - sum(a[i] - 1), add(a[i], 1);
        for (int i = 1; i <= n; i++)
            tot += l_low[i] * r_up[i] + l_up[i] * r_low[i];
        cout << tot << "\n";
    }
}

实在没看出来啥问题,也没越界啊

2023/12/18 23:06
加载中...