Title effect: Given n-$ a $ arranged, find that the whole arrangement ranking in $ $ n-
Solution: Cantor expanded to a full array, there is the first $ I $ $ n + 1-i $ choices, represented by the hexadecimal number change, which is a $ n + 1-i $ hexadecimal. First note arrangement $ [1, i) $ $ I $ than the first number of bits smaller digits $ a $, the first count variable binary bits is $ $ I $ ia-1 $. It can be used Fenwick tree maintenance
Card point: None
C++ Code:
#include <cstdio> #include <iostream> #include <algorithm> #define maxn 1000010 #define mul(a, b) (static_cast<long long> (a) * (b) % mod) const int mod = 998244353; inline void reduce(int &x) { x += x >> 31 & mod; } int fac[maxn], ans = 1, n; namespace BIT { int V[maxn], res; inline void add(int p) { for (; p <= n; p += p & -p) ++V[p]; } inline int query(int p) { for (res = 0; p; p &= p - 1) res += V[p]; return res; } } int main() { std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0); std::cin >> n; fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = mul(fac[i - 1], i); for (int i = 1, x; i <= n; ++i) { std::cin >> x; reduce(ans += mul(x - BIT::query(x) - 1, fac[n - i]) - mod); BIT::add(x); } std::cout << ans << '\n'; return 0; }