Problem B. Harvest of Apples time
limit:4000/2000 MS (java/others) Memory limit:262144/262144 K (java/ot Hers
Total submission (s): 347 Accepted Submission (s): 121
Problem Descriptionthere is $n $ apples on a tree, numbered from $1$ to $n $.
Count the number of ways to pick
at the most$m $ apples.
Inputthe first line of the input contains an integer $T $ $ (1 \le T \le ^ 5) $ denoting the number of test cases.
Each test case consists the one line with the integers $n, m$ $ (1 \le m \le N \le 10 ^ 5) $.
Outputfor each test case, print an integer representing the number of ways modulo $9 + 7$.
Sample Input25 21000 500
Sample Output16924129523
Source 2018 Multi-university Training Contest 4
Recommendchendu Analysis: The problem is obviously violent O (n^2) is to Tle, the game when considering simple mathematical optimization to become 2.5e9, obviously must also be tle. Later, considering the depth mathematical optimization, it is concluded that F1 represents hypergeometric function ... However, for more than half an hour, no templates were found for C + +. is very desperate to fill the question when found can use MO Team and sub-block to engage, learned a half day boingonium hindering, too food.
#include <iostream>#include<string>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<vector>#include<queue>#include<deque>#include<stack>#include<map>#defineLL Long Long#defineElif else if#defineRange (i,a,b) for (auto I=a;i<=b;++i)#defineRerange (i,a,b) for (auto i=a;i>=b;--i)#defineItrange (i,a,b) for (auto I=a;i!=b;++i)#defineFill (arr,tmp) memset (arr,tmp,sizeof (arr))using namespacestd;intt,n,m,block[int(2e5)],interval,id=1;structquery{intN,k,i;} q[int(1e5+5)];vector<query>ll[int(1e5+5)];BOOLcmp (query A,query b) {returna.n<B.N;}Const intMod=int(1e9+7); LL fac[int(1e5+5)],inv[int(1e5+5)],ans[int(1e5+5)]; ll Q_pow (ll A,ll b) {if(b<0)return 0; LL ret=1; A%=MoD; while(b) {ret=b&1? ret*a%Mod:ret; b>>=1; A=a*a%MoD; } returnret;} ll C (ll n,ll m) {if(n<m)return 0; returnfac[n]*inv[m]%mod*inv[n-m]%MoD;}voidinit () {fac[0]=1; Range (I,1,int(1E5)) fac[i]=fac[i-1]*i%MoD; inv[int(1E5)] =q_pow (fac[int(1e5)],mod-2); Rerange (i,int(1e5-1),0) inv[i]=inv[i+1]* (i+1)%MoD; Interval=int(sqrt (1e5)); for(intI=1; i<=int(1e5); i+=interval,++ID) for(intJ=i;j<i+interval and j<=int(1e5); ++j) block[j]=ID; --ID; scanf ("%d",&t); Range (I,1, T) {scanf ("%d%d",& (q+i)->n,& (q+i),k); (Q+i)->i=i; Ll[block[q[i].k]].push_back (Q[i]); }}voidSolve () {range (I,1, id)if(Ll[i].size ()) {sort (Ll[i].begin (), Ll[i].end (), CMP); LL Val=0,inch=ll[i][0].n,ik=-1; Range (J,0, Ll[i].size ()-1){ while(inch<LL[I][J].N) val= ((val<<1) +mod-c (inch++,ik))%MoD; while(IK<LL[I][J].K) val= (Val+c (inch, ++ik))%MoD; while(IK>LL[I][J].K) val= (Val+mod-c (inch, ik--))%MoD; ANS[LL[I][J].I]=Val; }} range (I,1, T) printf ("%lld\n", Ans[i]);}intMain () {init (); Solve (); return 0;}
View Code
HDU 6333:harvest of Apples