Description

给定三个正整数N、L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量。输出答案对10^6+3取模的结果。

Input

输入第一行包含一个整数T,表示数据组数。

第2到第T+1行每行包含三个整数N、L和R,N、L和R的意义如题所述。

1≤N,L,R≤10^9,1≤T≤100,输入数据保证L≤R。

Output

输出包含T行,每行有一个数字,表示你所求出的答案对10^6+3取模的结果。

Sample Input

2

1 4 5

2 4 5

Sample Output

2

5

//【样例说明】满足条件的2个序列为[4]和[5]。


思路

推一下式子发现答案是\(\sum_{i=1}^{n}C_{r-l+i}^i=C_{r-l+n+1}^n-1\)

#include<bits/stdc++.h>

using namespace std;

const int Mod = 1e6 + 3;

int f[Mod + 10];
int inv[Mod + 10], fac[Mod + 10]; int add(int a, int b) {
return (a += b) >= Mod ? a - Mod : a;
} int sub(int a, int b) {
return (a -= b) < 0 ? a + Mod : a;
} int mul(int a, int b) {
return 1ll * a * b % Mod;
} int fast_pow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = mul(res, a);
b >>= 1;
a = mul(a, a);
}
return res;
} void init() {
fac[0] = inv[0] = 1;
for (int i = 1; i < Mod; i++) fac[i] = mul(fac[i - 1], i);
inv[Mod - 1] = fast_pow(fac[Mod - 1], Mod - 2);
for (int i = Mod - 2; i >= 1; i--) inv[i] = mul(inv[i + 1], i + 1);
} int C(int a, int b) {
return mul(fac[a], mul(inv[b], inv[a - b]));
} int lucas(int a, int b) {
if (a < b) return 0;
if (a < Mod && b < Mod) return C(a, b);
return mul(C(a % Mod, b % Mod), lucas(a / Mod, b / Mod));
} int main() {
freopen("input.txt", "r", stdin);
init();
int T; scanf("%d", &T);
while (T--) {
int n, l, r;
scanf("%d %d %d", &n, &l, &r);
printf("%d\n", sub(lucas(r - l + n + 1, n), 1));
}
return 0;
}

BZOJ4403: 序列统计【lucas定理+组合数学】的更多相关文章

  1. Bzoj 4403: 序列统计 Lucas定理,组合数学,数论

    4403: 序列统计 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 328  Solved: 162[Submit][Status][Discuss] ...

  2. 【BZOJ4403】序列统计 Lucas定理

    [BZOJ4403]序列统计 Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案对10^6+3取模的结果. Input 输入第 ...

  3. BZOJ4403 序列统计—Lucas你好

    绝对是全网写的最详细的一篇题解  题目:序列统计 代码难度:简单 思维难度:提高+-省选 讲下题面:给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案 ...

  4. bzoj 4403 序列统计 卢卡斯定理

    4403:序列统计 Time Limit: 3 Sec  Memory Limit: 128 MB Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调 ...

  5. bzoj4403: 序列统计

    我们很容易发现答案是C(R-L+N+1,N)-1 然后用一下lucas定理就行了 #include <iostream> #include <cstdio> #include ...

  6. 2018.09.09 bzoj4403: 序列统计(Lucas定理)

    传送门 感觉单调不降序列什么的不好做啊. 于是我们序列中下标为i的元素的值加上i,这样就构成了一个单调递增的序列. 问题就变成了: 求出构造长度分别为1 ~ n且每个元素的值在l+1 ~ r+n之间的 ...

  7. bzoj4403 序列统计——组合数学

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4403 一开始想了个 O(n) 的做法,不行啊... O(n)想法是这样的:先考虑递推,设 f ...

  8. 【BZOJ4403】序列统计(组合数学,卢卡斯定理)

    [BZOJ4403]序列统计(组合数学,卢卡斯定理) 题面 Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案对10^6+3取 ...

  9. 【BZOJ4403】序列统计(Lucas定理,组合计数)

    题意:给定三个正整数N.L和R, 统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量. 输出答案对10^6+3取模的结果. 对于100%的数据,1≤N,L,R≤10^9,1≤T≤100, ...

随机推荐

  1. Python 爬虫-图片的爬取

    2017-07-25 22:49:21 import requests import os url = 'https://wallpapers.wallhaven.cc/wallpapers/full ...

  2. HTTP协议的请求与响应和CSS属性和定位

    HTTP协议的请求与响应和CSS属性和定位 一.HTTP协议 1.1 HTTP定义 HTTP(Hypertext Transport Protocol),超文本传输协议. 一种详细规定了浏览器和web ...

  3. yii CFormModel中的rules验证机制

    public function rules() { return array( array('username, password', 'required'), array('rememberMe', ...

  4. android------2018 年初值得关注的 16 个新 Android 库和项目

    1. transitioner Transitioner 是一个为两个拥有嵌入子视图的视图之间提供简便.动态且可调整的动画效果的库.它纯 100% 使用 Kotlin 编写而成,使用 MIT 许可,且 ...

  5. php--------对象(object) 与 数组(array) 的转换

    php开发中常常用到数组,sql数据都是数组,数组和对象用的也是比较多的,常常相互转化,数组是PHP的灵魂,非常强大,面向对象编程也是挺方便的. /** * 数组 转 对象 * * @param ar ...

  6. Confluence 6 连接一个目录

    你可以添加下面类型的目录服务器和目录管理器: Confluence 的内部目录(Configuring the Internal Directory). Microsoft Active Direct ...

  7. 【模板/经典题型】带有直线限制的NE Latice Path计数

    平移一下,变成不能接触y=x+1. 注意下面的操作(重点) 做点p=(n,m)关于这条直线的对称点q=(m-1,n+1). ans=f(p)-f(q). 其中f(x)为从(0,0)到点x的方案数.

  8. MySql 定时完成备份

    <?php /*定时备份数据库文件*/ //设置时区 date_default_timezone_set('PRC'); //创建目录 $dirname = 'e:/mysql_dump/'.d ...

  9. PHP header函数设置http报文头示例详解

    //定义编码 header( 'Content-Type:text/html;charset=utf-8 '); //Atom header('Content-type: application/at ...

  10. visio开发者图形分类个人爱好

    visio开发者图形分类个人爱好