On the field can not think out, see the standard process want to self-closing ...
#include <algorithm>#include<iostream>#include<cstdio>#include<vector>#include<cmath>using namespacestd;#defineN 100005#defineMoD 1000000007structquery{intN,k,i;} Q[n];BOOLcmpConstQuery&a,Constquery&b) { returna.n<B.N;}intReflect[n];/// chunkingvector<query>lis[ -];intFac[n],inv[n];intQuickintAintb) { intOdd =1; while(b) {if(b&1) Odd = 1ll*odd*a%MoD; A= 1ll*a*a%MoD; b>>=1; } returnOdd;}Const intMX =100000;voiddeal () {fac[0] =1; for(inti =1; I <= MX; ++i) {Fac[i]= 1ll*i*fac[i-1]%MoD; } INV[MX]= Quick (fac[mx],mod-2); for(inti = mx; I --i) {Inv[i-1] = 1ll*i*inv[i]%MoD; }}intRes[n];intCintNintm) { return1ll*fac[n]*inv[m]%mod*inv[n-m]%MoD;}intMain () {deal (); intcent =sqrt (MX); intCNT =1; for(inti =1; I <= MX; i + = cent, + +CNT) { for(intj = i; J <= MX and J <= i + cent; ++j) {Reflect[j]=CNT; } } intT; scanf ("%d",&T); for(inti =1; I <= T; ++i) {scanf ("%d%d",&q[i].n,&Q[I].K); Q[I].I=i; Lis[reflect[q[i].k]].push_back (Q[i]); } for(inti =1; I <= CNT; ++i)if(!Lis[i].empty ()) {Sort (Lis[i].begin (), Lis[i].end (), CMP); intval =0,inch= lis[i][0].n,ik =-1; for(Auto &J:lis[i]) { while(inch<J.N) val = (0ll + val + val + mod-c (inch++,ik))%MoD; while(IK<J.K) val = (val + C (inch, ++ik))%MoD; while(IK>J.K) val = (val + mod-c (inch, ik--))%MoD; RES[J.I]=Val; } } for(inti =1; I <= T; ++i) {printf ("%d\n", Res[i]); }}
Mark Cheng, worship.
HDU 6311 Harvest of Apples (number of combinations, MO team)