@[My_Xuan](/user/679265) 没开 long long
by pyy1 @ 2023-08-10 11:56:25
```cpp
#include <bits/stdc++.h>
#define int long long
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;
}
signed 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;
}
```
by pyy1 @ 2023-08-10 11:57:14
@[pyy1](/user/581316) 已通过,警示后人,thx
by My_Xuan @ 2023-08-10 12:00:49