捷径?歧路?怎么写啊?(#33942)

ScdH 2020-02-14 19:41:00 2020-02-14 19:54:48

代码公开: 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 条回复

Imagine Dragons

牛蛙老哥~~~

题是啥意思都不明白

不知道

赵玉佳(北川)

不会粘贴复制

张含硕

把第一行改成#include<bits/stdc++.h>就能过了

明金烁

为什么还是过不了

明金烁