Sum of the products of 51nod 1348

Source: Internet
Author: User

The sum of all the schemes (0<=i<=r-l+1) multiplied by the number of f[l,r in the interval [l,r] is represented by the (r-l+2) dimension vector], which can be found f[l,r]=f[l,m]*f[m+1,r], the topic modulus 100003 is smaller, The upper bound of the answer is approximately 1e16 after each convolution, the CRT can be combined with NTT in the two-1e9 modulus, the complexity is O (nlog2n), and the constant optimization should be noted.

#include <cstdio>#include<cstring>#include<algorithm>typedefLong Longi64;int _(){    intx=0, f=1, c=GetChar ();  while(c< -) c=='-'&& (f=-1), c=GetChar ();  while(c> -) x=x*Ten+c- -, c=GetChar (); returnx*F;}intPowintAintNintp) {    intv=1;  for(; n;n>>=1){        if(n&1) v=i64 (v) *a%p; A=i64 (a) *a%p; }    returnv;} I64 Mul (i64 a,i64 b,i64 p) {i64 s=0; A%=p;b%=p;  while(b) {if(b&1) (S+=a)%=p; (A<<=1)%=p; b>>=1; }    returns;}intn,x,r[262144];template<Const intPConst intG>voidNttint*a,intt) {     for(intI=0; i<n;++i)if(i>R[i]) Std::swap (A[i],a[r[i]);  for(intI=1; i<n;i<<=1){        intW=pow (g, (t* (P-1)/(i*2) +p-1), p);  for(intj=0;j<n;j+=i<<1){            intE=1, *b=a+j,*c=b+i;  for(intk=0; k<i;++k,e=i64 (e) *w%p) {                intX=b[k],y=c[k]*i64 (e)%p; B[K]= (x+y)%p; C[K]= (x-y+p)%p; }        }    }    if(t==-1) {i64 I=pow (n,p-2, p);  for(intI=0; i<n;++i) a[i]=a[i]*i%p; }}intn,q,v0[50007],mem[65536* -+7],*mp=mem,vs[4][65536+7];Const intp1=998244353, g1=3, p2=950009857, g2=7;ConstI64 m1=i64 (p1) *pow (p1,p2-2, p2), m2=i64 (p2) *pow (p2,p1-2, p1), ps=i64 (p1) *P2;int*calc (intLintR) {    int*pos=mp;mp+=r-l+1; if(l==R) {        *pos=V0[l]; returnPOS; }    intM=l+r>>1; int*lp=calc (l,m)-1; int*rp=calc (m+1, R)-1;  for(n=2, x=0; n<r-l+2; n<<=1,++X); if(r-l+1<= -){         for(intI=0;i<2; ++i) memset (Vs[i],0Nsizeof(int)), vs[i][0]=1;  for(intI=1; i<=m-l+1; ++i) vs[0][i]=Lp[i];  for(intI=1; i<=r-m;++i) vs[1][i]=Rp[i];  for(intI=1; i<=r-l+1;++i) {             for(intj=0; j<=i;++j) pos[i-1]= (pos[i-1]+i64 (vs[0][J]) *vs[1][I-J])%100003; }        returnPOS; }     for(intI=1; i<n;++i) r[i]=r[i>>1]>>1| (i&1) <<y;  for(intI=0;i<4; ++i) memset (Vs[i],0Nsizeof(int)), vs[i][0]=1;  for(intI=1; i<=m-l+1; ++i) vs[0][i]=vs[1][i]=Lp[i];  for(intI=1; i<=r-m;++i) vs[2][i]=vs[3][i]=Rp[i]; NTT<p1,g1> (vs[0],1); NTT<p1,g1> (vs[2],1); NTT<p2,g2> (vs[1],1); NTT<p2,g2> (vs[3],1);  for(intI=0; i<n;++i) vs[0][i]=i64 (vs[0][i]) *vs[2][i]%P1;  for(intI=0; i<n;++i) vs[1][i]=i64 (vs[1][i]) *vs[3][i]%P2; NTT<p1,g1> (vs[0],-1); NTT<p2,g2> (vs[1],-1);  for(intI=1; i<=r-l+1; ++i) pos[i-1]= (Mul (m2,vs[0][I],PS) +mul (m1,vs[1][I],PS))%ps%100003; returnPos;}intMain () {n=_ (); q=_();  for(intI=1; i<=n;++i) v0[i]=_(); int*ans=calc (1, N)-1;  while(q--) printf ("%d\n", Ans[_ ()]); return 0;}

Sum of the products of 51nod 1348

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.