HDU - 6333 Harvest of Apples
题意:
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的更多相关文章
- HDU 6333 Harvest of Apples (分块、数论)
题目连接:Harvest of Apples 题意:给出一个n和m,求C(0,n)+C(1,n)+.....+C(m,n).(样例组数为1e5) 题解:首先先把阶乘和逆元预处理出来,这样就可O(1)将 ...
- 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 题意很好懂,就是组合数求和. 官方题解: 我来叨叨 ...
- hdu多校第4场 B Harvest of Apples(莫队)
Problem B. Harvest of Apples Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...
- 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 ...
- Harvest of Apples
问题 B: Harvest of Apples 时间限制: 1 Sec 内存限制: 128 MB提交: 18 解决: 11[提交] [状态] [讨论版] [命题人:admin] 题目描述 Ther ...
- HDU 6333 莫队+组合数
Problem B. Harvest of Apples Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K ...
- hdu6333 Harvest of Apples 离线+分块+组合数学(求组合数模板)
Problem B. Harvest of Apples Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K ...
- 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) 设 ...
- 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 ...
随机推荐
- jQuery wordexport导出 word
同事给我说了简单的导出word的插件,亲测了下,做个随笔. 这个导出插件是jQuery自带的的插件,通过调用wordexport.js来实现导出功能. 1.引入的js <script type= ...
- nodejs 事件机制
node 事件机制 一 三种定时器 NodeJS中有三种类型的定时器:超时时间.时间间隔.即时定时器 1.超时时间:setTimeout(callback,delayMilliSeconds,[a ...
- java 前后端 日期转换
1.前传后 @DateTimeFormat(pattern="yyyy-MM-dd") private Date payTime; 2.后传前 @JsonFormat(patter ...
- Django模型与创建管理员用户
默认情况下, 配置使用SQLite:
- SQL 从入门到 DBA 删库跑路
SQL 从入门到 DBA 删库跑路 一.基础 人员信息表: ID 姓名 性别 出生 婚否 学历 工资 工会 35009449 孙xx 男 1978-2-17 未婚 中专 3000 TRUE 35000 ...
- mysql新手进阶02
云想衣裳花想容,春风拂槛露华浓. 若非群玉山头见,会向瑶台月下逢. 现在有一教学管理系统,具体的关系模式如下: Student (no, name, sex, birthday, class) Tea ...
- Objective-C Block数据类型 @protocol关键字
Block数据类型 Block封装了一段代码 可以在任何时候执行 Block可以作为函数参数或者函数的返回值 而其本身又可以带输入参数或返回值 苹果官方建议尽量多用Block 在多线程 异步任务 集合 ...
- TPO-13 C2 How to use language lab
TPO-13 C2 How to use language lab 第 1 段 1.Listen to a conversation between a student and the languag ...
- Linux中常用Shell命令
本随笔文章,由个人博客(鸟不拉屎)转移至博客园 写于:2018 年 05 月 04 日 原地址:https://niaobulashi.com/archives/linux-shell.html -- ...
- Vue 编程之路(三)—— Vue 中子组件在父组件的 v-for 循环里,父组件如何调取子组件的事件
(标题的解决方案在第二部分) 最近公司的一个项目中使用 Vue 2.0 + element UI 实现一个后台管理系统的前端部分,属于商城类型. 一.前期思路: 其中在“所有订单”页面,UI 给的设计 ...