CodeForces 689E Mike and Geometry Problem
离散化,树状数组,组合数学。
这题的大致思路和$HDU$ $5700$一样。都是求区间交的问题。可以用树状数组维护一下。
这题的话只要计算每一个$i$被统计了几次,假设第$i$点被统计了$ans[i]$次,累加和就是答案。
$ans[i]$就是看$i$点之后有多少个区间右端点,假设有$m$个,那么$ans[i]$就等于$m$个里面选$k$个的方案数。
因为数据中$L$,$R$范围较大,所以需要先离散化,计算离散化之后的情况,然后再统计离散化之前的情况。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c=getchar(); x=;
while(!isdigit(c)) c=getchar();
while(isdigit(c)) {x=x*+c-''; c=getchar();}
} LL mod=1e9+;
const int maxn=;
int n,k;
LL f[maxn],a[maxn];
struct X { int L,R; }s[maxn];
int c[maxn],b[maxn],sz;
LL ans[maxn]; int lowbit(int x){return x&(-x);}
int sum(int x)
{
int res=;
while(x>) res=res+c[x],x=x-lowbit(x);
return res;
}
void update(int x,int v)
{
while(x<=) c[x]=c[x]+v,x=x+lowbit(x);
} LL extend_gcd(LL a,LL b,LL &x,LL &y)
{
if(a==&&b==) return -;
if(b==){x=;y=;return a;}
LL d=extend_gcd(b,a%b,y,x);
y-=a/b*x;
return d;
} LL mod_reverse(LL a,LL n)
{
LL x,y;
LL d=extend_gcd(a,n,x,y);
if(d==) return (x%n+n)%n;
else return -;
} int get(int x)
{
int L=,R=sz-,pos=;
while(L<=R)
{
int mid=(L+R)/;
if(b[mid]<x) L=mid+;
else if(b[mid]==x) pos=mid,R=mid-;
else R=mid-;
}
return pos+;
} bool cmp(X a,X b) { return a.L<b.L; } int main()
{
scanf("%d%d",&n,&k);
f[]=; for(int i=;i<=;i++) f[i]=i*f[i-]%mod;
for(int i=k;i<=;i++)
{
LL fz=f[i]%mod,fm=f[k]*f[i-k]%mod;
LL ni=mod_reverse(fm,mod);
a[i]=fz*ni%mod;
} for(int i=;i<=n;i++)
{
scanf("%d%d",&s[i].L,&s[i].R);
b[sz++]=s[i].L, b[sz++]=s[i].R;
b[sz++]=s[i].L-; b[sz++]=s[i].L+;
b[sz++]=s[i].R-; b[sz++]=s[i].R+;
} sort(b,b+sz);
sort(s+,s++n,cmp); int h=;
for(int i=;i<=sz;i++)
{
while(h<=n&&get(s[h].L)==i)
{
update(get(s[h].R),);
h++;
}
ans[i]=a[sum()-sum(i-)];
} LL Ans=;
for(int i=;i<sz;)
{
int pos=-;
for(int j=i;j<sz;j++)
{
if(b[j]>b[i]) { pos=j; break; }
}
if(pos==-) { Ans=(Ans+ans[i+])%mod; break; }
Ans=(Ans+(b[pos]-b[i])*ans[i+]%mod)%mod;
i=pos;
} printf("%lld\n",Ans);
return ;
}
CodeForces 689E Mike and Geometry Problem的更多相关文章
- CodeForces 689E Mike and Geometry Problem (离散化+组合数)
Mike and Geometry Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/I Description M ...
- codeforces 689E E. Mike and Geometry Problem(组合数学)
题目链接: E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化 排列组合
E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】
任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化+逆元
E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes input ...
- codeforces 361 E - Mike and Geometry Problem
原题: Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him ...
- Codeforces 798C. Mike and gcd problem 模拟构造 数组gcd大于1
C. Mike and gcd problem time limit per test: 2 seconds memory limit per test: 256 megabytes input: s ...
- 【算法系列学习】codeforces C. Mike and gcd problem
C. Mike and gcd problem http://www.cnblogs.com/BBBob/p/6746721.html #include<iostream> #includ ...
- codeforces#410C Mike and gcd problem
题目:Mike and gcd problem 题意:给一个序列a1到an ,如果gcd(a1,a2,...an)≠1,给一种操作,可以使ai和ai+1分别变为(ai+ai+1)和(ai-ai+1); ...
随机推荐
- ios中判断控制台Log输出控制,是否是iphone5,自动调整尺寸
// 控制台Log输出控制,此确保在release版本下无Log输出 #ifdef DEBUG #define CMBLOG NSLog #else #define CMBLOG ...
- PHP 5.5以后加速插件:Zend Opcache
大家知道目前PHP的缓存插件一般有三个: APC. eAccelerator. XCache,但未来它们可能都会消失,因为PHP 5.5已经集成 Zend Opcache,功能和前三者相似但又有少许不 ...
- 解决Timer回调方法重复调用的问题
如果Timer的回调方法的执行时间很长,计时器可能在上个回调方法还没有完成的时候再次触发,如果我们只是想让一个回调方法执行完后再执行下一个回调方法,可以这样: private static Timer ...
- rcp(插件开发) The activator X for bundle Y is invalid 解决办法
最近在做插件产品的重构,重构的过程当中难免有一些细节的地方 忘记修改 ,导致出现莫名的问题. 比如这个问题: The activator X for bundle Y is invalid 这个问题从 ...
- [整理]在命令行执行 UIAutomation
instruments -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/Automati ...
- 企业架构研究总结(29)——TOGAF架构内容框架之概述及架构工作产品分类
在TOGAF 9之前的版本中,TOGAF的重点主要集中在企业架构开发方法方面,用于指导其使用者如何在各自的组织中对企业架构进行创建和维护,而对于企业架构的具体内容并没有相关的论述,因而针对早期TOGA ...
- WCF/WPF公司内部订餐程序开发
WCF/WPF公司内部订餐程序开发 (服务端篇) 上班的第一天,群里讨论关于订餐的问题,所以想到了要不要自己开发一个公司内部的订餐系统呢?方便公司内部员工的订餐,有了想法就简单的实践了下 . 实现还是 ...
- CentOS5、6 NFS的安装配置及mount方法
一.环境介绍: 服务器:centos 192.168.1.225 客户端:centos 192.168.1.226 二.安装: NFS的安装配置:centos 5 : yum -y install n ...
- Easyui表单验证扩展
简介: 使用Easyui,我们省了好多事情,不用为UI费心,只需要关注业务层面即可,下面是一些常用的验证方面的扩展,收藏下自己用 //重载$.fn.validatebox.defaults.rules ...
- c# winform 在一个窗体中使用另一个窗体中TextBox控件的值——解决办法
[前提]一个winform应用程序项目中,窗体B,需要使用 窗体A 中一个TextBox控件的值,进行计算等操作. [解决方案] 1.在窗体A中定义:public static double a;// ...