离散化,树状数组,组合数学。

这题的大致思路和$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的更多相关文章

  1. CodeForces 689E Mike and Geometry Problem (离散化+组合数)

    Mike and Geometry Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/I Description M ...

  2. codeforces 689E E. Mike and Geometry Problem(组合数学)

    题目链接: E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 【算法系列学习】codeforces C. Mike and gcd problem

    C. Mike and gcd problem http://www.cnblogs.com/BBBob/p/6746721.html #include<iostream> #includ ...

  9. 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); ...

随机推荐

  1. c# 窗体最小化后截图实现

    我们知道,当我们需要对Control进行截图时,我们可以使用Control.DrawToBitmap()进行截图, 那么问题来了,当我们的窗体最小化了,我们还怎么截图呢? 当窗体最小化的时候,我们知道 ...

  2. js读取 存入cookie

    <script language=javascript> //获得coolie 的值 function cookie(name){ var cookieArray=document.coo ...

  3. Oracle和Mysql分别生成sequence序列

    有时候在往数据库中插入数据的时候,如果ID值是32位的UUID, 而自己随便写个字符又不合适,这时就要用到函数来产生一个序列值 Oracle: select sys_guid() from dual; ...

  4. Modern 阅读笔记 一 PSR标准

    一.标准 PSR php standards Recommendation PHP 推荐标准 PSR-1 基本代码风格 PSR-2 严格的代码风格  PSR-3 日志记录器接口 PSR-4 自动加载  ...

  5. 导出&导入

    导出&导入 上一文中,我们大致明白了,利用MEF框架实现自动扫描并组装扩展组件的思路.本文我们继续前进,从最初的定义公共接口开始,一步步学会如何使用MEF. 在上一文中我们知道,对于每一个实现 ...

  6. WPF4.5新特性(MSDN的翻译读不太懂)

    WPF4.5新特性(MSDN的翻译读不太懂) 1. 新的Doctype声明 XHTML的声明太长了,我相信很少会有前端开发人员能手写出这个Doctype声明. <!DOCTYPE html PU ...

  7. Arduino 各种模块篇 蓝牙模块 手机蓝牙控制Arduino LED灯

    解决方案. 条件: 1.手机android 商店下载 blueTerm 2.向arduino中载入如下代码: char val; ; void setup() { Serial.begin(); pi ...

  8. jQuery 1.10.2 and 2.0.3 Released

    t’s nearly Independence Day here in the USA, so we’re delivering something fresh off the grill: jQue ...

  9. Debian下的'aptitude update'失败处理

    Hit http://ftp.us.debian.org squeeze/contrib amd64 Packages Hit http://download.proxmox.com squeeze/ ...

  10. android JNI--- 搭建环境(1)

    搭建好我们的ndk开发环境,这部分网上资料一大堆,拿来主义~~~~ 工欲善其事必先利其器 , 下面介绍下 Eclipse SDK NDK Cygwin CDT 集成开发环境的搭建. 1.Android ...