4332:jsoi2012 Snack Time limit:10 Sec Memory limit:256 MB
submit:119 solved:66 Description here is the joyful pilgrimage river, here is the joyful kindergarten. Today is February 14, Tuesday. On this special day, the teacher danced happily with his classmates and smiled. The headmaster bought a lot of snacks from the snack bar next to the kindergarten and decided to give them to the students. Hearing the news, all the students quietly lined up the team, we all know that the headmaster does not like naughty children. The students lined up in a row, including a child, with three common happiness coefficients o,s and U. If a child gets x candies, then her happiness level is f (x) =o*x2+s*x+u. Now the headmaster began to divide the candy, there are a total of M candy. Some children may not get candy, for those who do not get candy, the level of happiness is 1. If a child does not get candy, then the children behind her will not get candy. (That is, the list of children who do not get candy must be the last number of consecutive bits) all the points of candy are equal probability. Now the question is: what is the product of the happiness of all the children in the expected circumstances? The students soon have a train of thought, as long as the total program number T and all schemes under the sum of the Happiness degree product of S, you can get the answer ans=s/t. Now he has asked for the answer to T, but how does s ask? He had no idea. Can you tell him? Because the answer is very big, you just need to tell him the result of s p-modulo. PostScript: Although we all know, even if we know T, know the result of s p modulo, there is no way to know the expected situation, all children happy degree of product. But when I thought about it, I was completely desperate. The first line of input has 2 integers, m and p, respectively. The second line has an integer a, and the third line has an integer o. Row Four has an integer s, and the fifth line has an integer U. Output an integer s, because the answer can be large, you only need to export s to p modulo results. Sample Input 4 100
4
1
0
0Sample Output 63
Sample Description
function f (x) =x^2. A total of 4 snacks, 4 students. If only the first classmate to get, the level of happiness is 16, if the first two students get, the level of happiness all may be 9,9,16, if there are three students, the degree of happiness 4,4,4, the last situation, each classmate has been snacks, the level of happiness is 1. Add and get s=63.
Should the uploader request, this question is not public, if have objection, please raise.HINT
For 100% of data, m<=10000,p<=255,a<=108,o<=4,s<=300,u<=100.
Source
Analysis
I got it from 7.
Understand grandpa's code for a long time ah ... But the play is really short ...
The following qpow is a fast power for matrix multiplication!! "I was silly to look at it for a long time.
So ask $g^1+g^2+ ... g^n$
Oh "I watched this for a long time
"Hehe
Actually, I think this convolution is a little crazy.
But whatever it is, we'll talk tomorrow.
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <cmath>7 using namespacestd;8 #defineMAXN 10010*49 Const DoublePi=acos (-1);Ten intMod; One A structP - { - Doublex, y; theP () {x=y=0;} -PDoubleXDoubley): x (x), Y (y) {} -Friend Poperator+ (P x,p y) {returnP (x.x+y.x,x.y+y.y);} -Friend Poperator-(P x,p y) {returnP (x.x-y.x,x.y-y.y);} +Friend Poperator* (P x,p y) {returnP (x.x*y.x-x.y*y.y,x.x*y.y+x.y*y.x);} - }A[MAXN],B[MAXN]; + A intr[maxn],nn,m; at voidDFT (P *a,intf) - { - for(intI=0; i<nn;i++)if(i<R[i]) swap (a[i],a[r[i]); - for(intI=1; i<nn;i<<=1) - { -P wn (cos (pi/i), F*sin (pi/i)); in for(intj=0;j<nn;j+=i<<1) - { toP W (1,0); + for(intk=0; k<i;k++,w=w*WN) - { theP x=a[j+k],y=w*a[j+k+i]; *a[j+k]=x+y;a[j+k+i]=x-y; $ }Panax Notoginseng } - } the if(f==-1) + { A for(intI=0; i<=nn;i++) a[i].x/=nn,a[i].y/=nn; the } + } - $ intA[MAXN],B[MAXN],C[MAXN],NW[MAXN]; $ intaa,bb,cc; - voidFftint*a,int*B) - { the for(intI=0; i<nn;i++) - {Wuyia[i].x=a[i];a[i].y=0; theb[i].x=b[i];b[i].y=0; - } WuDFT (A,1);d ft (b,1); - for(intI=0; i<=nn;i++) a[i]=a[i]*B[i]; AboutDFT (a,-1); $ for(intI=1; i<=m;i++) a[i]= ((int) (a[i].x+0.5)%Mod); - } - - voidAddint*a,int*B) A { + for(intI=1; i<=m;i++) a[i]= (A[i]+b[i])%Mod; the } - $ voidQpow (intk) the { the for(intI=0; i<=m;i++) a[i]=0; the for(intI=1; i<=m;i++) c[i]=b[i]= (AA*I*I+BB*I+CC)%Mod; the while(k) - { in if(k&1) the { the FFT (A, b); About Add (a,c); the } the for(intI=1; i<=m;i++) nw[i]=C[i]; the FFT (c,b); + Add (C,NW); - FFT (b,b); thek>>=1;Bayi } the } the - intMain () - { the intN; thescanf"%d%d%d%d%d%d",&m,&mod,&n,&aa,&bb,&cc); the if(n>m) n=m; thenn=1;intLl=0; - while(nn<=2*M) nn<<=1, ll++; the for(intI=0; i<=nn;i++) r[i]= (r[i>>1]>>1)| ((i&1) << (ll-1)); the Qpow (n); theprintf"%d\n", A[m]);94 return 0; the}View Code
2017-04-14 21:46:24
"Bzoj 4332" 4332:jsoi2012 snack (fft+ fast power)