比赛 |
NOIP2023模拟赛3 |
评测结果 |
WWTTTTTTTT |
题目名称 |
期望逆序对 |
最终得分 |
0 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
8.123 s |
代码语言 |
C++ |
内存使用 |
51.51 MiB |
提交时间 |
2023-11-15 12:31:55 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e6+10,mod = 1e9+7;
int n;
ll k,p = 1e9+7,ans;
ll a[N],s[N] = {1,1},c[N];
ll pow(ll x,ll y){
if(y == 0)return 1;
ll ans = pow(x,y/2) % mod;
if(y % 2)return ((ans * ans) % mod * x) % mod;
else return (ans * ans) % mod;
}
ll C(ll x,ll y){
return ((s[x] * pow(s[x-y],p-2)) % mod * pow(s[y],p-2)) % mod;
}
ll ask(ll x){
ll ans = 0;
for(;x > 0;x -= x & -x)ans += c[x];
return ans;
}
void add(ll x){
if(x == 0)return;
for(;x <= n;x += x & -x)c[x]++;
}
void check(){
memset(c,0,sizeof(c));
for(int i = n;i >= 1;i--){
ans = (ans + ask(a[i]-1)) % mod;
add(a[i]);
}
}
int main(){
freopen("starlit.in","r",stdin);
freopen("starlit.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i = 2;i <= n;i++)s[i] = (s[i-1] * i) % mod;
for(int i = 1;i <= n;i++)scanf("%lld",&a[i]);
for(int i = 1;i <= n;i++){
for(int j = i+1;j <= n;j++){
swap(a[i],a[j]);
check();
swap(a[i],a[j]);
}
}
printf("%lld\n",((ans * pow(C(n,2),p-2)) % mod * pow(C(n,2),k)) % mod);
return 0;
}