题解:P17762 「奶龙OI」Round 3 - 跑酷大神
Ethereal_Wu · · 题解
题意
给定一个数列
将
思路
我们发现考虑所有的数列并逐个求交集是困难的。因此转化题意。我们考察所有数轴上的点,对于每个点
对于整点
现在考虑计数。这
综上,答案是
时间复杂度为
代码
#include <iostream>
#include <algorithm>
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define MIKU 0
using namespace std;
const int mod = 998244353;
int T;
int n, a[400005], fac[200005];
int qpow(int a, int n, int res=1) {
for(; n; n>>=1) {
if(n & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
void init() {
fac[0] = 1;
for(int i=1; i<=200005; i++) fac[i] = fac[i-1] * i % mod;
}
void work() {
cin>>n;
for(int i=1; i<=2*n; i++) cin>>a[i];
sort(a+1, a+2*n+1);
int d = a[n+1] - a[n];
int ans = d * fac[n] % mod * fac[n] % mod * qpow(2, n) % mod;
cout<<ans<<'\n';
}
signed main() {
fastio;
cin>>T;
init();
while(T--) work();
return MIKU;
}