10pts求调
查看原帖
10pts求调
679265
My_Xuan楼主2023/8/10 11:30
#include <bits/stdc++.h>
using namespace std;
#define lb(n) n & -n

const int mod = 998244353, N = 1e6 + 5;
int n, ans, a, c[N], f[N] = {1, 1};

void update (int x, int y)
{
	while (x <= n) c[x] += y, x += lb(x);
}

int query (int x)
{
	int sum = 0;
	while (x) sum += c[x], sum %= mod, x -= lb(x);
	return sum % mod;
}

int main ( )
{
	ios :: sync_with_stdio (0); cin.tie (0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		f[i] = (f[i - 1] * i) % mod, update (i, 1);
	for (int i = 1; i <= n; i++)
	{
		cin >> a;
		ans = (ans + ((query (a) - 1) * f[n - i]) % mod) % mod;
		update (a, -1);
	}
	cout << ans + 1;
	return 0;
}

除了#1,2外,其余全WA,求调,不胜感激

2023/8/10 11:30
加载中...