「PKUSC2018」真实排名
题面
题解
因为操作为将一些数字翻倍,
所以对于一个数\(x\),
能影响它的排名的的只有满足\(2y\geq x\)或\(2x>y\)的\(y\)
将选手的成绩排序,然后考虑当前点的方案
1. 不翻倍
此时,如果要保证\(x\)的排名不变,那么所有满足\(2y \geq x\)的\(y\)都不能动
设满足\(2y \geq x\)的数有\(\mathrm{Len}\)个,则方案数为\(\binom{n-\mathrm{Len}}{k}\)
2. 翻倍
此时,如果要保证\(x\)的排名不变,那么所有满足\(2x > y\)的\(y\)都要动
设满足\(2x > y\)的数有\(\mathrm{Len}\)个,则方案数为\(\binom{n-\mathrm{Len}}{k-\mathrm{Len}}\)
如果有相同的怎么办???
去重之后,将\(0\)和其他的数字分开处理即可。
代码
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<vector>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x))
inline int read()
{
int data = 0, w = 1; char ch = getchar();
while(ch != '-' && (!isdigit(ch))) ch = getchar();
if(ch == '-') w = -1, ch = getchar();
while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
return data * w;
}
const int maxn(1e5 + 10), Mod(998244353), N(maxn - 10);
struct node { int val, id, cnt; } A[maxn], B[maxn];
inline bool cmp(const node &lhs, const node &rhs) { return lhs.val < rhs.val; }
int fastpow(int x, int y)
{
int ans = 1;
while(y)
{
if(y & 1) ans = 1ll * ans * x % Mod;
x = 1ll * x * x % Mod, y >>= 1;
}
return ans;
}
int sum[maxn];
int fac[maxn], inv[maxn];
int n, K, ans[maxn], tot;
std::vector<int> S[maxn];
inline int C(int n, int m)
{
if(n < m || n < 0 || m < 0) return 0;
return 1ll * fac[n] * inv[m] % Mod * inv[n - m] % Mod;
}
int main()
{
fac[0] = inv[0] = 1;
for(RG int i = 1; i <= N; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
inv[N] = fastpow(fac[N], Mod - 2);
for(RG int i = N - 1; i; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
n = read(), K = read();
for(RG int i = 1; i <= n; i++) B[i] = (node) {read(), i, 1};
std::sort(B + 1, B + n + 1, cmp); B[0] = (node) {-1, -1, 0};
for(RG int i = 1; i <= n; i++)
if(B[i].val != B[i - 1].val)
{ ++tot; A[tot] = B[i]; S[tot].push_back(B[i].id); }
else ++A[tot].cnt, S[tot].push_back(B[i].id);
for(RG int i = 1; i <= tot; i++)
sum[i] = sum[i - 1] + A[i].cnt;
for(RG int i = 1, R = 1; i <= tot; i++)
{
while(R < tot && A[i].val * 2 > A[R + 1].val) ++R;
int Len = sum[R] - sum[i - 1];
if(A[i].val == 0) Len = sum[R] - sum[i] + 1;
if(Len <= K)
for(RG int j = 0, l = S[i].size(); j < l; j++)
ans[S[i][j]] = (ans[S[i][j]] + C(n - Len, K - Len)) % Mod;
}
for(RG int i = tot, L = tot; i; i--)
{
while(L > 1 && A[L - 1].val * 2 >= A[i].val) --L;
int Len = sum[i - 1] - sum[L - 1] + 1;
for(RG int j = 0, l = S[i].size(); j < l; j++)
ans[S[i][j]] = (ans[S[i][j]] + C(n - Len, K)) % Mod;
}
for(RG int i = 1; i <= n; i++) printf("%d\n", ans[i]);
return 0;
}