题意:

  T次询问,每次给出n,m。求sigma(k:0->m)C(n, k)。

题解:

  用离线莫队来做。

  令S(n,m) = sigma(k:0->m)C(n, k)。

  S(n+1, m) = 2S(n, m) - C(n, m)   S(n-1, m) = (S(n, m) + C(n-1, m)) / 2

  S(n, m+1) = S(n, m) + C(n, m+1)   S(n, m-1) = S(n, m) - C(n, m)

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+;
const int N = 1e5+;
int t;
int blk;
int blg[N];
int fac[N], inv[N], tmp[N];
int l, r, now;
int ans[N];
struct ask {
int l, r, id;
bool operator < (const ask &a) {
return blg[l] == blg[a.l] ? r < a.r : l < a.l;
}
}q[N];
int C(int n, int m) {
int res = 1ll*fac[n]*inv[m]%mod;
res = 1ll*res*inv[n-m]%mod;
return res;
}
void update(int k, int t) {
if(t == ) {
if(~k) now = (2ll*now-C(l, r)+mod)%mod;
else now = 1ll*(now+C(l-, r))*tmp[]%mod;
}
else {
if(~k) now = (now+C(l, r))%mod;
else now = (now-C(l, r)+mod)%mod;
}
}
int main() {
fac[] = fac[] = tmp[] = inv[] = inv[] = ;
for(int i = ; i < N; i++) {
fac[i] = 1ll*fac[i-]*i%mod;
tmp[i] = 1ll*(mod-mod/i)*tmp[mod%i]%mod;
inv[i] = 1ll*inv[i-]*tmp[i]%mod;
}
scanf("%d", &t);
int up = ;
for(int i = ; i <= t; i++) {
scanf("%d%d", &q[i].l, &q[i].r);
up = max(up, q[i].r);
q[i].id = i;
}
blk = sqrt(t);
for(int i = ; i <= up; i++) blg[i] = (i-)/blk;
sort(q+, q+t+);
now = ;
l = , r = ;
for(int i = ; i <= t; i++) {
while(r > q[i].r) update(-, ), r--;
while(l < q[i].l) update(, ), l++;
while(l > q[i].l) update(-, ), l--;
while(r < q[i].r) r++, update(, );
ans[q[i].id] = now;
}
for(int i = ; i <= t; i++) printf("%d\n", ans[i]);
}

  

HDU - 6333 Harvest of Apples的更多相关文章

  1. HDU 6333 Harvest of Apples (分块、数论)

    题目连接:Harvest of Apples 题意:给出一个n和m,求C(0,n)+C(1,n)+.....+C(m,n).(样例组数为1e5) 题解:首先先把阶乘和逆元预处理出来,这样就可O(1)将 ...

  2. HDU 6333.Problem B. Harvest of Apples-组合数C(n,0)到C(n,m)求和-组合数学(逆元)+莫队 ((2018 Multi-University Training Contest 4 1002))

    2018 Multi-University Training Contest 4 6333.Problem B. Harvest of Apples 题意很好懂,就是组合数求和. 官方题解: 我来叨叨 ...

  3. hdu多校第4场 B Harvest of Apples(莫队)

    Problem B. Harvest of Apples Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...

  4. 2018 Multi-University Training Contest 4 Problem B. Harvest of Apples 【莫队+排列组合+逆元预处理技巧】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 Problem B. Harvest of Apples Time Limit: 4000/200 ...

  5. Harvest of Apples

    问题 B: Harvest of Apples 时间限制: 1 Sec  内存限制: 128 MB提交: 18  解决: 11[提交] [状态] [讨论版] [命题人:admin] 题目描述 Ther ...

  6. HDU 6333 莫队+组合数

    Problem B. Harvest of Apples Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  7. hdu6333 Harvest of Apples 离线+分块+组合数学(求组合数模板)

    Problem B. Harvest of Apples Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  8. hdu6333 Problem B. Harvest of Apples(组合数+莫队)

    hdu6333 Problem B. Harvest of Apples 题目传送门 题意: 求(0,n)~(m,n)组合数之和 题解: C(n,m)=C(n-1,m-1)+C(n-1,m)    设 ...

  9. Problem B. Harvest of Apples HDU - 6333(莫队)

    Problem Description There are n apples on a tree, numbered from 1 to n.Count the number of ways to p ...

随机推荐

  1. python的阶段复习

    1.ABCD乘于9 = DCBA,求ABCD的值,且ABCD均互不相等 #!/usr/bin/env python # -*- coding:utf-8 -*- # @Time :2017/12/26 ...

  2. 海思NB-IOT死机问题解决记录

    1. 首先抓下LOG的信息,这个应该是MCU到NB的数据 2. 看下NB到MCU的数据 3. 总结起来,只看到了NB模块的启动,似乎AT指令,肯本没收到.测试中确实出现了复位,但是不清楚是发送的AT指 ...

  3. ubuntu14.04上安装Java

    apt-get安装 sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install orac ...

  4. solr 常见的问题整理 -费元星

    本文是我在开发过程中遇到的一些问题的整理,有些摘自网上别人的方法. 1. org.apache.solr.client.solrj.SolrServerException: Timeout occur ...

  5. C 关键字 标示符 注释

    一 关键字 1. 什么是关键字 关键字就是C语言提供的有特殊含义的符号 也叫做"保留字" C语言一共提供了32个关键字 这些关键字都被C语言赋予了特殊含义 auto double ...

  6. TPO-16 C1 Reserve the room for a rehearsal

    TPO-16 C1 Reserve the room for a rehearsal 第 1 段 1.Listen to a conversation between a Student and a ...

  7. 常用linux命令相关

    [查看端口] netstat -tlnp netstat命令 netstat -an | grep 3306 3306替换成需要grep的端口号 lsof命令 通过list open file命令可以 ...

  8. rsync+inotify实现实时同步,自动触发同步文件

    本文参考来自:http://chocolee.blog.51cto.com/8158455/1400596 我的需求和他的略有不同,同时做了一下更改,如下: 需求:两台机器相互为主备,搭建相同的两个服 ...

  9. Ubuntu 配置 ftp freemind adb

    . 1. 配置apt-get源 配置过程 : sudo vim /etc/profile 命令, 在后面添加下面的内容; 刷新配置文件 : source /etc/profie 命令; 刷新源 : s ...

  10. Tomcat服务器学习和使用(一)

    一.Tomcat服务器端口的配置 Tomcat的所有配置都放在conf文件夹之中,里面的server.xml文件是配置的核心文件. 如果想修改Tomcat服务器的启动端口,则可以在server.xml ...