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

这题的大致思路和$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. Django数据库迁移

    如果你用过Django的数据库就会发现一个比较令人纠结的地方:数据库更改. 我们知道添加或者删除一个models.Model 需要在数据库里相应的操作,这需要我们进入数据库命令行手动添加或删除,因为s ...

  2. iOS开发技术分享(1)— iOS本地数据存储

    iOS开发技术分享(1)— iOS本地数据存储 前言: 我本是一名asp.net程序员,后来加入了iOS游戏开发队伍,到现在也有一年多的时间了.这一年来,每天都干到2.3点钟才睡觉,不为别的,只为了学 ...

  3. 实用的android颜色配置表(亮瞎尼的双眼)

    android开发中,常常会用到color.xml颜色配置,好的颜色配置可以让尼的应用让人看起来赏心悦目! 不罗嗦,上图先 该工程已经罗列了常用的颜色配置 附上工程链接:http://download ...

  4. HTTP协议 HttpWebRequest和 Socket的一点总结

    HTTP协议 HttpWebRequest和 Socket的一点总结 相信接触过网络开发的人对HTTP.HttpWebRequest.Socket这些东西都不陌生吧.它们之间的一些介绍和关系我这里都忽 ...

  5. 做了一个quartz用到的cron在线生成器

    做了一个quartz用到的cron在线生成器 做了一个quartz用到的cron在线生成器   做这个的目的是前期在做Quartz时老是不知道如何去写,我想也有很多人和我一样吧. 有一次使用了一个老外 ...

  6. 对C# 构造函数的理解

    C#构造函数是在创建给定类型的对象时执行的类方法. 构造函数具有与类相同的名称,它通常初始化新对象的数据成员.不带参数的构造函数称为“默认构造函数”. 无论何时,只要使用 new 运算符实例化对象,并 ...

  7. 挖一下插件v1.5版本发布

    Chrome图片下载插件,支持网页截屏 v.1.5更新说明: 1.增加下载图片按日期分类保存选项,便于管理,用户可根据需要开启/关闭此设置 2.增加网页图片采集快捷键: (1)采集页面图片(Ctrl+ ...

  8. sql server数据库中删除的过程

    这是在vb中的一个对数据库中数据的删除过程,点击按钮后程序第一句则是将你要删除的那条记录的位置作为书签保存到myBookmark这个变量里面,然后选择确定删除的话,首先执行if语句下的第一句 mrc. ...

  9. DEV gridcontrol 设置行数据超宽换行

    第一 在main > columns 的 某个gridcolumn下的 columnEdit为新建为 repositoryitemmemoedit 第二 repositor下的optionvie ...

  10. Python学习入门基础教程(learning Python)--2.3.3Python函数型参详解

    本节讨论Python下函数型参的预设值问题. Python在设计函数时,可以给型参预设缺省值,当用户调用函数时可以不输入实参.如果用户不想使用缺省预设值则需要给型参一一赋值,可以给某些型参赋值或不按型 ...