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]的时 ...
随机推荐
- RabbitMQ常用的几种消息模型
第一种模型(HelloWorld) 上图来自官方文档 P代表生产者用来生产消息,发送给消费者C,中间的共色部分代表消息队列,用来缓存消息. 首先导入依赖 <dependency> < ...
- 深入汇编指令理解Java关键字volatile
volatile是什么 volatile关键字是Java提供的一种轻量级同步机制.它能够保证可见性和有序性,但是不能保证原子性 可见性 对于volatile的可见性,先看看这段代码的执行 flag默认 ...
- 如何利用Intellij Idea搭建python编译运行环境 (转)
首先进入Intellij Idea的官方网站:点击打开链接 点击download,选择旗舰版进行下载.网上的破解教程很多,也可以注册一个学生账号拿到一年的免费试用权. 安装过程不再细说,第一次打开选择 ...
- 【Oracle】创建用户配额总是不足的解决问题 quota
在oracle中,正常创建的用户是没有配额限制的,也就是默认的是unlimited on tablespace的,但是在有些时候,没有设置相关的配额,用户总是会报错用户配额严重不足,查看表空间,也有很 ...
- Promise.all()使用实例
一.什么是Promise.all()? 在说这个之前要先说清楚promise.promise就是一个对象,专门用来处理异步操作的. 而Promise.all方法用于将多个 Promise 实例,包装成 ...
- 响应式编程库RxJava初探
引子 在读 Hystrix 源码时,发现一些奇特的写法.稍作搜索,知道使用了最新流行的响应式编程库RxJava.那么响应式编程究竟是怎样的呢? 本文对响应式编程及 RxJava 库作一个初步的探索. ...
- JVM(二)类加载的时机及其过程
类从被加载到虚拟机内存中开始,到卸载出内存为止,它的的整个生命周期包括: 加载(Loading),验证(Verification),准备(Preparation),解析(Resolution),初始化 ...
- jQuery 真伪数组的转换
//真数组转换伪数组 var arr = [1,3,5,7,9]; var obj = {}; [].push.apply(obj,arr); console.log(obj) //伪数组转真数组 v ...
- 什么是 MVC 模式
概述 MVC,即 Model 模型.View 视图,及 Controller 控制器. View:视图,为用高糊提供使用界面,与用户直接进行交互. Model:模型,承载数据,并对用户提交请求进行计算 ...
- ensure that both new and old access_token values are available within five minutes, so that third-party services are smoothly transitioned.
WeChat public doc https://developers.weixin.qq.com/doc/offiaccount/en/Basic_Information/Get_access_t ...