题录:P4859 已经没有什么好害怕的了 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
思路:

代码:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
using namespace std;
#define LL long long
const int N = 2e3 + 100;
const long long mod = 1e9+9;
LL n, k;
LL a[N], b[N], F[N][N], f[N], g[N],fc[N],c[N];
LL quick(LL a, LL b, LL mod)
{
LL ans = 1;
while (b)
{
if (b & 1) ans = ans * a % mod;
b = b >> 1;
a = a * a % mod;
}
return ans;
}
void into()
{
c[0] = 1;
for (int i = 1; i <= n; i++) c[i] = (LL)c[i - 1] * i % mod;
for (int i = 0; i <= n; i++) fc[i] = quick(c[i], mod - 2, mod);
}
int seek(int num,int x)
{
int l = 1, r = n, ans=0,mid;
while (l <= r)
{
mid = (l + r) >> 1;
if (a[num] > b[mid])
ans = mid, l = mid + 1;
else
r = mid - 1;
}
return ans - x < 0 ? 0 : ans - x;
}
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
into();
if ((n + k)%2)
{
cout << 0 << endl;
return 0;
}
F[0][0] = 1;
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + n);
for (int i = 1; i <= n; i++)
{
F[i][0] = 1;
for (int j = 1; j <= i; j++)
{
int pos = seek(i,j-1);
F[i][j] = (F[i - 1][j] + F[i - 1][j - 1] * pos)%mod;
}
}
LL ans = 0;
int now = (n + k) >> 1;
for (int j = now; j <= n; j++)
{
LL res = (LL)F[n][j] * c[n - j]%mod;
res = (LL)res * c[j] % mod * fc[now] % mod * fc[j - now] % mod;
if ((j-now) % 2) res *= -1;
ans = (ans + res) % mod;
}
cout << (ans%mod+mod)%mod << endl;
return 0;
}