bzoj:4105: [Thu Summer Camp 2015] Square operation

Source: Internet
Author: User
Tags gcd

Description

Input

The first line has three integer n,m,p that represent the length of the sequence, the total number of square operations and query operations, and the number of modules to be modeled in the square operation.

The next row n number represents the beginning of the sequence {x1,x2,..., XN}. Next m line, three integers per line op,l,r. Where OP represents the type of the operation. If Op=0, represents this is a square operation, the square of the interval is [l,r]; if op=1, this is an inquiry operation, the interval of inquiry is [L,r]. Output

For each query operation, the output line represents the sum of the numbers in the interval. Note: The answer is not modeled on any number.

Sample Input3 3 11
1 2 3
1 1 3
0 1 3
1 1 3Sample Output6
-HINT

For 100% of data, ∀i,xi∈[0,p), L,r∈[1,n]


The scope of the n,m,p is as follows:

NumberN M p
1 233
2 2332
3100000 100000 5
4100000 100000 8192
5100000 100000
6100000 100000
7100000 100000 Notoginseng
855000 55000 4185
955000 55000 5850
1055000 55000 2975
1155000 55000 2542
1255000 55000
1360000 60000 2003
1465000 65000
1570000 70000 4593
1675000 75000 4562
1780000 80000 1034
1885000 85000 5831
1990000 90000 9905
20100000 100000 9977 The film has a lot of The line tree is certain ... The square is a circular section (I hear it will be very short pre-processing all the rings, and the chain pointing to the ring, because there is no other modification operation, the number is definitely the more changes to the ring run, into the ring to deal with the run K times after the answer is how much, not on the ring on the violence change ... on the importance of the authority number
/************************************************************** problem:4105 user:jszx11556 language:c++ result:accepted time:25216 Ms memory:275236 kb****************************************************************/#include<cstdio>#include<algorithm>#defineLP (P&LT;&LT;1)#defineRP ((p<<1) |using namespacestd;intRead_p,read_ca;inlineintRead () {read_p=0; read_ca=GetChar ();  while(read_ca<'0'|| Read_ca>'9') read_ca=GetChar ();  while(read_ca>='0'&&read_ca<='9') read_p=read_p*Ten+read_ca- -, read_ca=GetChar (); returnread_p;}intn,m,p,a[100001],ne[100001],i;BOOLv[100001],f[100001];structna{intl,r,w,le,c,b[ the],pos; BOOLv;} t[1000000];inlineintgcdintXintY) {returny==0? X:GCD (y,x%y);} InlineintLcmintXintY) {returnx*y/gcd (x, y);} InlinevoidUpdata (intp) {    if(T[P].L==T[P].R)return; T[P].W=t[lp].w+T[RP].W; T[P].V=t[lp].v&t[rp].v; if(T[P].V) {T[p].pos=0; T[p].le=LCM (T[lp].le,t[rp].le);  for(i=0; i<t[p].le;i++) t[p].b[i]=t[lp].b[(i+t[lp].pos)%t[lp].le]+t[rp].b[(i+t[rp].pos)%T[rp].le]; }}inlinevoidBuildintPintLintR) {T[P].L=l;t[p].r=R; if(l==R) {T[P].W=a[l];t[p].v=F[T[P].W]; if(T[P].V) for(t[p].b[0]=t[p].w,t[p].le=1, I=ne[t[p].w];i!=t[p].w;i=ne[i]) t[p].b[t[p].le++]=i; return; }    intMid=l+r>>1; Build (Lp,l,mid); Build (Rp,mid+1, R); Updata (P);} InlinevoidHbintPintc) {    if(!t[p].v) {         for(i=1; i<=c;i++) t[p].w=ne[t[p].w];t[p].v=F[T[P].W]; if(T[P].V) for(t[p].b[0]=t[p].w,t[p].le=1, I=ne[t[p].w];i!=t[p].w;i=ne[i]) t[p].b[t[p].le++]=i; return; } C%=T[p].le; T[P].C+=c;if(T[p].c>=t[p].le) t[p].c-=T[p].le; T[p].pos+=c;if(T[p].pos>=t[p].le) t[p].pos-=T[p].le; T[P].W=T[p].b[t[p].pos];} InlinevoidPdintp) {    if(t[p].c) {if(t[p].l!=T[P].R) HB (LP,T[P].C), HB (RP,T[P].C); T[P].C=0;    Updata (P); }}inlinevoidChintPintLintR) {    if(T[P].L==L&AMP;&AMP;T[P].R==R&AMP;&AMP;T[P].V)returnHB (P,1);    PD (P); if(t[p].l==T[P].R) {T[P].W=ne[t[p].w];t[p].v=F[T[P].W]; if(T[P].V) for(t[p].b[0]=t[p].w,t[p].le=1, I=ne[t[p].w];i!=t[p].w;i=ne[i]) t[p].b[t[p].le++]=i; return; }    intMid=t[p].l+t[p].r>>1; if(r<=mid) ch (lp,l,r);Else    if(l>mid) ch (rp,l,r);ElseCH (lp,l,mid), CH (rp,mid+1, R); Updata (P);} InlineintMMH (intPintLintR)    {PD (P); if(T[P].L==L&AMP;&AMP;T[P].R==R)returnT[P].W; intMid=t[p].l+t[p].r>>1; if(R<=mid)returnMMH (LP,L,R);Else    if(L>mid)returnMMH (RP,L,R);Else    returnMMH (Lp,l,mid) +mmh (rp,mid+1, R);}intMain () {registerintI,j,t,l,r; N=read (); m=read (); P=read ();  for(i=1; i<=n;i++) a[i]=read ();  for(i=0; i<p;i++) ne[i]=i*i%p,f[i]=1;  for(i=0; i<p;i++)    if(!V[i]) {         for(j=i;! V[J];J=NE[J]) v[j]=1;  for(t=i; T!=j; T=ne[t]) f[t]=0; } Build (1,1, N);  for(i=1; i<=m;i++) {T=read (); L=read (); r=read (); if(T) printf ("%d\n", MMH (1, l,r));ElseCh1, L,r); }}
View Code

bzoj:4105: [Thu Summer Camp 2015] Square operation

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.