【BZOJ4403】序列统计

来源:互联网 发布:python 下划线用法 编辑:程序博客网 时间:2024/06/10 05:59

Description

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

Input

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

Output

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

Sample Input

21 4 52 4 5
Sample Output

25

HINT

提示

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

【数据规模和约定】对于100%的数据,1≤N,L,R≤10^9,1≤T≤100,输入数据保证L≤R。

Source

By yts1999
答案是C(r-l+1+n,n)-1
Lucas一下

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define GET (ch>='0'&&ch<='9')#define P 1000003#define LL long longusing namespace std;int T,n,l,r;int fac[P+10]={1};int Pow(int a,int b){    int ret=1;a%=P;    for (;b;a=(LL)a*a%P,b>>=1)  if (b&1)    ret=(LL)ret*a%P;    return ret;}void in(int &x){    char ch=getchar();x=0;    while (!GET)    ch=getchar();    while (GET) x=x*10+ch-'0',ch=getchar();}int C(int n,int m){    return n<m?0:(int)((LL)fac[n]*Pow(fac[m],P-2)%P*Pow(fac[n-m],P-2)%P);}int lucas(int n,int m){    int ret=1;    for (;n||m;n/=P,m/=P)   ret=(LL)ret*C(n%P,m%P)%P;    return ret;}int main(){    for (int i=1;i<=P;i++)  fac[i]=(LL)fac[i-1]*i%P;    for (in(T);T;T--)    {        in(n);in(l);in(r);        printf("%d\n",(lucas(r-l+1+n,n)-1+P)%P);    }}
1 0