Loj 6432. 「PKUSC2018」真实排名 (组合数)
题面
题解
枚举每一个点
分两种情况
翻倍or不翻倍
\(1.\)如果这个点\(i\)翻倍, 要保持排名不变,哪些必须翻倍,哪些可以翻倍?
必须翻倍: \(a[i] \leq a[x] < a[i]*2\)
那么其他的都可以选择性翻倍
\(2.\) 考虑点\(i\)不翻倍,
不能翻倍的: \(a[i]/2 \leq a[x] < a[i]\)
注意有和\(a[i]\)相等的可以翻倍
以上可以排序后,二分+组合数算
细节比较多,具体看代码
Code
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int N = 100010;
const ll Mod = 998244353;
ll ksm(ll x, ll y) {
ll s = 1;
while (y) {
if (y & 1) s = s * x % Mod;
y >>= 1;
x = x*x%Mod;
}
return s;
}
ll fac[N];
ll C(int n, int m) {
if (n < m || n < 0 || m < 0) return 0;
return fac[n]*ksm(fac[m], Mod-2)%Mod*ksm(fac[n-m], Mod-2)%Mod;
}
int a[N], b[N];
template<class T> inline void read(T &x) {
x = 0; char c = getchar(); bool f = 0;
while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
x = f ? -x : x;
return ;
}
int main() {
int n, k;
read(n); read(k);
for (int i = 1; i <= n; i++) read(a[i]), b[i] = a[i];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i-1]*i%Mod;
sort(b+1, b+1+n);
for (int i = 1; i <= n; i++) {
if (!a[i]) {
printf("%lld\n", C(n, k));
continue;
}
ll ans1 = 0, ans2 = 0;
int x1 = lower_bound(b+1, b+1+n, (a[i]+1)/2) - b - 1;
int x2 = lower_bound(b+1, b+1+n, a[i]) - b;
ans1 = C(x1+n-x2, k);
int x3 = lower_bound(b+1, b+1+n, a[i]*2) - b;
ans2 = C(n - x3 + x2, k - x3 + x2);
printf("%lld\n", (ans1 + ans2) % Mod);
}
return 0;
}
Loj 6432. 「PKUSC2018」真实排名 (组合数)的更多相关文章
- LOJ #6432. 「PKUSC2018」真实排名(组合数)
题面 LOJ #6432. 「PKUSC2018」真实排名 注意排名的定义 , 分数不小于他的选手数量 !!! 题解 有点坑的细节题 ... 思路很简单 , 把每个数分两种情况讨论一下了 . 假设它为 ...
- Loj#6432「PKUSC2018」真实排名(二分查找+组合数)
题面 Loj 题解 普通的暴力是直接枚举改或者不改,最后在判断最后对哪些点有贡献. 而这种方法是很难优化的.所以考虑在排序之后线性处理.首先先假设没有重复的元素 struct Node { int p ...
- LOJ #6432. 「PKUSC2018」真实排名
题目在这里...... 对于这道题,现场我写炸了......谁跟我说组合数O(n)的求是最快的?(~!@#¥¥%……& #include <cstdio> #include < ...
- LOJ 6432 「PKUSC2018」真实排名——水题
题目:https://loj.ac/problem/6432 如果不选自己,设自己的值是 x ,需要让 “ a<x && 2*a>=x ” 的非 x 的值不被选:如果选自己 ...
- 【LOJ】#6432. 「PKUSC2018」真实排名
题解 简单分析一下,如果这个选手成绩是0,直接输出\(\binom{n}{k}\) 如果这个选手的成绩没有被翻倍,那么找到大于等于它的数(除了它自己)有a个,翻倍后不大于它的数有b个,那么就从这\(a ...
- #6432. 「PKUSC2018」真实排名(组合数学)
题面 传送门 题解 这数据范围--这输出大小--这模数--太有迷惑性了-- 首先对于\(0\)来说,不管怎么选它们的排名都不会变,这个先特判掉 对于一个\(a_i\)来说,如果它不选,那么所有大于等于 ...
- 「PKUSC2018」真实排名(排列组合,数学)
前言 为什么随机跳题会跳到这种题目啊? Solution 我们发现可以把这个东西分情况讨论: 1.这个点没有加倍 这一段相同的可以看成一个点,然后后面的都可以. 这一段看成一个点,然后前面的不能对他造 ...
- 「PKUSC2018」真实排名(组合)
一道不错的组合数问题! 分两类讨论: 1.\(a_i\) 没有翻倍,那些 \(\geq a_i\) 和 \(a_j\times 2<a_i\) 的数就没有影响了.设 \(kth\) 为 \(a_ ...
- 「PKUSC2018」真实排名
题面 题解 因为操作为将一些数字翻倍, 所以对于一个数\(x\), 能影响它的排名的的只有满足\(2y\geq x\)或\(2x>y\)的\(y\) 将选手的成绩排序,然后考虑当前点的方案 1. ...
随机推荐
- 【bzoj2705】[SDOI2012]Longge的问题
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2507 Solved: 1531[Submit][ ...
- Java-Decimal
import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; public c ...
- ROS源码解读(一)--局部路径规划
博客转载自:https://blog.csdn.net/xmy306538517/article/details/78772066 ROS局部路径导航包括Trajectory Rollout 和 Dy ...
- c语言解二元二次方程组
设a和b是正整数 a+b=30 且a*b=221 求a和b的值 思路就是穷举a和b的值,每次得到a和b的一个值,看是否同时满足a+b=30且a*b=221,如果满足,那么就输出. 那么a和b的的取值范 ...
- Luogu 4155 [SCOI2015]国旗计划
BZOJ 4444 倍增 + 贪心. 发现是一个环,先按照套路把环断开复制一倍,这样子的话覆盖完整个环就相当于覆盖一条长度不小于$m$的链,注意这样子有一些区间在新的这条链上会出现两次. 我们为了找到 ...
- 数据结构 Merge合并排序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- getContextPath、getServletPath、getRequestURI,getRealPath的区别
假定你的web application 项目名称为news,你在浏览器中输入请求路径: http://localhost:8080/news/main/list.jsp 则执行下面向行代码后打印出如下 ...
- su 和sudo su 的区别
su "user" 执行该命令,需要输入password,它是"user"中定义的用户的password,即,要变换成的用户的password.(如果已经用ro ...
- Codeforces 12D Ball(线段树)
N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty ...
- timer实现Grid自动换行(连续相同的id跳到下一行)
private { Private declarations } FRow: Integer; procedure SetRow(const Value: Integer); public { Pub ...