Codeforces Round #678 (Div. 2) C. Binary Search (二分,组合数)

题意:有长度\(n\)的序列,让你构造序列,使得二分查找能在\(pos\)位置找到值\(x\).问最多能构造出多少种排列?
题解:题目给出的\(pos\)是固定的,所以我们可以根据图中所给的代码来进行二分,确定有多少数小于\(x\)和大于\(x\),然后根据排列组合即可算出答案.
代码:
int n,x,pos;
ll fac[N]; ll f[N],invf[N];
ll fpow(ll a,ll k){
ll res=1;
while(k){
if(k&1) res=(res*a)%mod;
k>>=1;
a=a*a%mod;
//cout<<1<<endl;
}
return res;
} void init(int n){
f[0]=1;
for(int i=1;i<=n;++i){
f[i]=f[i-1]*i%mod;
}
invf[n]=fpow(f[n],mod-2);
for(int i=n-1;i>=0;--i){
invf[i]=invf[i+1]*(i+1)%mod;
}
} ll C(int n,int k){
if(k<0 || k>n) return 0;
return f[n]*invf[k]%mod*invf[n-k]%mod;
} int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>x>>pos;
init(n); int l=0,r=n;
int L=0,R=0;
while(l<r){
int mid=(l+r)>>1;
if(mid<=pos){
if(mid!=pos) L++;
l=mid+1;
}
else R++,r=mid;
} fac[0]=1;
for(int i=1;i<=n;++i){
fac[i]=fac[i-1]%mod*i%mod;
} cout<<C(x-1,L)%mod*fac[L]%mod*C(n-x,R)%mod*fac[R]%mod*fac[n-L-R-1]%mod<<endl; return 0;
}
Codeforces Round #678 (Div. 2) C. Binary Search (二分,组合数)的更多相关文章
- Codeforces Round #678 (Div. 2)
Codeforces Round #678 (Div. 2) A. Reorder 题意:有一个有 n 个数的序列 a ,以及一个数 m ,问能否给序列a重新排序,能够满足式子 $\sum_{i=1} ...
- Codeforces Round #678 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1436 A. Reorder 题解 模拟一下这个二重循环发现每个位置数最终都只加了一次. 代码 #include <bi ...
- Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum
E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个 ...
- Codeforces Round #598 (Div. 3) D. Binary String Minimizing 贪心
D. Binary String Minimizing You are given a binary string of length n (i. e. a string consisting of ...
- Codeforces Round #598 (Div. 3) D. Binary String Minimizing
You are given a binary string of length nn (i. e. a string consisting of nn characters '0' and '1'). ...
- Codeforces Round #651 (Div. 2) E. Binary Subsequence Rotation(dp)
题目链接:https://codeforces.com/contest/1370/problem/E 题意 给出两个长为 $n$ 的 $01$ 串 $s$ 和 $t$,每次可以选择 $s$ 的一些下标 ...
- 【Codeforces Round #440 (Div. 2) A】 Search for Pretty Integers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 先枚举一个数字的情况. 再枚举两个数的情况就好. [代码] #include <bits/stdc++.h> #defi ...
- Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum (二进制,前缀和)
题意:有两个\(01\)字符串\(a\)和\(b\),每次让\(a\)和\(b\)进行与运算,将值贡献给答案,然后将\(b\)右移一位,直到\(b=0\). 题解:因为\(a\)不变,而\(b\)每次 ...
- Codeforces Round #353 (Div. 2) D. Tree Construction (二分,stl_set)
题目链接:http://codeforces.com/problemset/problem/675/D 给你一个如题的二叉树,让你求出每个节点的父节点是多少. 用set来存储每个数,遍历到a[i]的时 ...
随机推荐
- 【Linux】sudo配置文件讲解
一.sudo执行命令的流程 将当前用户切换到超级用户下,或切换到指定的用户下, 然后以超级用户或其指定切换到的用户身份执行命令,执行完成后,直接退回到当前用户. 具体工作过程如下: 当用户执行sudo ...
- 安装macosx10.13high serria
本教程所需资源下载链接: 链接:https://pan.baidu.com/s/1wGTezXz6zGvtlwpv6mMoSg 提取码:r6n9 安装VMware workstation 16.0,安 ...
- 5V-12V输入输出的限流芯片,可调限至4.8A
可是在输出电压模式:3.6V,5V,12V 在输出3.6V模式:输入电压范围2.5V-4.5V,输入关闭电压5V,限流最大4.8A 在输出5V模式,输入电压范围3.8V-6V,输输入过电压关闭6V,限 ...
- scrapy的大文件下载(基于一种形式的管道类实现)
scrapy的大文件下载(基于一种形式的管道类实现) 爬虫类中将解析到的图片地址存储到item,将item提交给指定的管道 在管道文件中导包:from scrapy.pipelines.images ...
- Py层次递进与文件修改大程序,模块,name与file
层次的递进与返回 #输入quit的时候返回上一阶层,输入exit退出所有的循环 tag=True while tag==True: level1=input('level1:') if level1= ...
- 【Android初级】如何动态添加菜单项(附源码+避坑)
我们平时在开发过程中,为了灵活多变,除了使用静态的菜单,还有动态添加菜单的需求.今天要分享的功能如下: 在界面的右上角有个更多选项,点开后,有两个子菜单:关于和退出 点击"关于", ...
- CentOS安装mysql、JDK、Tomcat部署环境
1.1. 安装mysql-5.6 1.1.1. 检测系统内部有没有安装其他的mysql数据库 $ rpm -qa | grep mysql 1.1.2. 如果内部有需要先删除Mysql $ yum r ...
- ArchLinux安装后所需要的环境和工具
ArchLinux安装后所需要的环境和工具 工具: Dolphin 文件管理器 ntfs-3G 移动硬盘挂载 octopi 实时检查更新 KDE Connect 手机电脑远程连接 DBeaver Co ...
- 接口 Interfaces
Interfaces - zope.interface 5.0.2.dev0 documentation https://zopeinterface.readthedocs.io/en/latest/ ...
- Centos 7 安装 erlang
https://www.cnblogs.com/swyy/p/11582309.html https://blog.csdn.net/qq_20492999/article/details/81254 ...