题面

题解

因为操作为将一些数字翻倍,

所以对于一个数\(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;
}

「PKUSC2018」真实排名的更多相关文章

  1. LOJ #6432. 「PKUSC2018」真实排名(组合数)

    题面 LOJ #6432. 「PKUSC2018」真实排名 注意排名的定义 , 分数不小于他的选手数量 !!! 题解 有点坑的细节题 ... 思路很简单 , 把每个数分两种情况讨论一下了 . 假设它为 ...

  2. 「PKUSC2018」真实排名(排列组合,数学)

    前言 为什么随机跳题会跳到这种题目啊? Solution 我们发现可以把这个东西分情况讨论: 1.这个点没有加倍 这一段相同的可以看成一个点,然后后面的都可以. 这一段看成一个点,然后前面的不能对他造 ...

  3. 「PKUSC2018」真实排名(组合)

    一道不错的组合数问题! 分两类讨论: 1.\(a_i\) 没有翻倍,那些 \(\geq a_i\) 和 \(a_j\times 2<a_i\) 的数就没有影响了.设 \(kth\) 为 \(a_ ...

  4. 【LOJ】#6432. 「PKUSC2018」真实排名

    题解 简单分析一下,如果这个选手成绩是0,直接输出\(\binom{n}{k}\) 如果这个选手的成绩没有被翻倍,那么找到大于等于它的数(除了它自己)有a个,翻倍后不大于它的数有b个,那么就从这\(a ...

  5. LOJ #6432. 「PKUSC2018」真实排名

    题目在这里...... 对于这道题,现场我写炸了......谁跟我说组合数O(n)的求是最快的?(~!@#¥¥%……& #include <cstdio> #include < ...

  6. Loj 6432. 「PKUSC2018」真实排名 (组合数)

    题面 Loj 题解 枚举每一个点 分两种情况 翻倍or不翻倍 \(1.\)如果这个点\(i\)翻倍, 要保持排名不变,哪些必须翻倍,哪些可以翻倍? 必须翻倍: \(a[i] \leq a[x] < ...

  7. #6432. 「PKUSC2018」真实排名(组合数学)

    题面 传送门 题解 这数据范围--这输出大小--这模数--太有迷惑性了-- 首先对于\(0\)来说,不管怎么选它们的排名都不会变,这个先特判掉 对于一个\(a_i\)来说,如果它不选,那么所有大于等于 ...

  8. Loj#6432「PKUSC2018」真实排名(二分查找+组合数)

    题面 Loj 题解 普通的暴力是直接枚举改或者不改,最后在判断最后对哪些点有贡献. 而这种方法是很难优化的.所以考虑在排序之后线性处理.首先先假设没有重复的元素 struct Node { int p ...

  9. LOJ 6432 「PKUSC2018」真实排名——水题

    题目:https://loj.ac/problem/6432 如果不选自己,设自己的值是 x ,需要让 “ a<x && 2*a>=x ” 的非 x 的值不被选:如果选自己 ...

随机推荐

  1. C# 标准的MD5加密32位

    标准的MD5加密32位小写的: public static string GetMD5(string myString) { MD5 md5 = new MD5CryptoServiceProvide ...

  2. windows 端口映射

    netsh interface portproxy add v4tov4 listenport=8765 listenaddress=0.0.0.0 connectaddress=172.19.24. ...

  3. 获取INET4与INET6的信息

    获取INET4与INET6的信息 参考书籍: 本人封装的源码: // // IPAddressInfo.h // YXNETWORK // // http://www.cnblogs.com/YouX ...

  4. Linux uname命令详解

    uname常见命令参数 -a, --all print all information, in the following order, except omit -p and -i if unknow ...

  5. eclipse中 项目-->属性-->为什么没有deployment assembly 选项

    原因: 因为当前的maven工程不是web工程,需要转换成web工程. 解决方法: 右击工程属性,找到Project Facets,选择Dynamic Web Module,2.5 点击apply.这 ...

  6. 一、BOM 二、DOM

    一.BOM(window对象)###<1>window属性对象 window.location 当前浏览器的地址对象 window.history 浏览器访问过的地址对象 window.o ...

  7. November 13th 2016 Week 47th Sunday The 1st Day

    Adventure may hurt you, but monotony will kill you. 也许冒险会让你受伤,但一成不变会让你灭亡. Just change a bit, let the ...

  8. November 6th 2016 Week 46th Sunday

    The starting point of all achievements is desire. 成功的第一步是渴望. Those who make great achievements are o ...

  9. 字符串到-->list到-->字典的转变

    怎么把字符串变成字典呢?? 要先转成列表list(用split方法),然后再把列表转成字典,这时候就用到-->怎么把列表转换成字典呢??列表的索引和字典的新增,然后就能把字符串转成字典了.

  10. PHP设计模式系列 - 单例

    单例模式 通过提供自身共享实例的访问,单例设计模式用于限制特定对象只能被创建一次. 使用场景 例如数据库实例,一般都会走单例模式. 单例模式可以减少类的实例化 代码:来源InitPHP框架,先检测类有 ...