代码公开: AC代码:
#include #include
typedef long long lld;
const int N = 1e5 + 9, mod = 1e9 + 7; int n, m, a[N], frac[N], tr[N];
inline int lowbit(int x) { return x & (-x); } void insert(int x) { while (x <= n) { ++tr[x]; x += lowbit(x); } } int query(int x) { int s = 0; while (x) { s += tr[x]; x -= lowbit(x); } return s; }
int cantor() { memset(tr, 0, sizeof tr);
int s = 0;
for (int i = 0; i < n; ++i) {
int t = (n - a[i]) - (i - query(a[i]));
insert(a[i]);
s = (s + (lld)t * frac[n - 1 - i]) % mod;
}
return (s + 1) % mod;
}
int main() { scanf("%d%d", &n, &m);
frac[0] = 1;
for (int i = 1; i < n; ++i) frac[i] = (lld)frac[i - 1] * i % mod;
while (m--) {
for (int i = 0; i < n; ++i) scanf("%d", a + i);
printf("%d\n", cantor());
}
}
共 7 条回复
牛蛙老哥~~~
题是啥意思都不明白
不知道
不会粘贴复制
把第一行改成#include<bits/stdc++.h>就能过了
为什么还是过不了