HDU4578 Transformation Segment Tree

Source: Internet
Author: User

This problem has taught me to re-learn the operation of multiply in the interval.

Puzzle: Http://blog.csdn.net/guognib/article/details/25324025?utm_source=tuicool&utm_medium=referral

Code: Also refer to the above written

Note: There is really a priority, plus only affect themselves, multiply will affect the plus, reset value will clear 0 all the marks

So when you go down, multiply and add the operation is later than the last set value, and then multiply the operation to precede the addition

So first pass the set and then the Mul and then the Add.

#include <stdio.h>#include<string.h>#include<string>#include<math.h>#include<stack>#include<vector>#include<algorithm>using namespaceStd;typedefLong LongLL;Const intn=1e5+5;Const intMod=10007;intq[3][n<<2],setval[n<<2],add[n<<2],mul[n<<2];voidPushup (intRT) {     for(intI=0;i<3;++i) Q[i][rt]= (q[i][rt<<1]+q[i][rt<<1|1])%MoD; }voidDownset (intRtintCintLen) {    inta[4];a[1]=C;  for(intI=2; i<=3;++i) a[i]=a[i-1]*a[1]%MoD;  for(intI=0;i<3;++i) Q[i][rt]=a[i+1]*len%MoD; SETVAL[RT]=C; ADD[RT]=0; MUL[RT]=1;}voidDownadd (intRtintCintLen) {    inta[4];a[1]=C;  for(intI=2; i<=3;++i) a[i]=a[i-1]*a[1]%MoD; q[2][rt]=q[2][rt]+a[3]*len%mod+3*a[2]%mod*q[0][rt]%mod+3*a[1]%mod*q[1][rt]%MoD; q[1][rt]=q[1][rt]+a[2]*len%mod+2*a[1]%mod*q[0][rt]%MoD; q[0][rt]=q[0][rt]+a[1]*len%MoD;  for(intI=0;i<3; ++i) q[i][rt]%=MoD; ADD[RT]= (add[rt]+c)%MoD;}voidDownmul (intRtintCintLen) {   inta[4];a[1]=C;  for(intI=2; i<=3;++i) a[i]=a[i-1]*a[1]%MoD;  for(intI=0;i<3;++i) Q[i][rt]= (q[i][rt]*a[i+1])%MoD; MUL[RT]= (mul[rt]*c)%MoD; ADD[RT]= (add[rt]*c)%MoD;}voidDownintRtintLintR) {    intM= (l+r) >>1; if(setval[rt]!=-1) {downset (RT<<1, setval[rt],m-l+1); Downset (Rt<<1|1, setval[rt],r-m); SETVAL[RT]=-1; }    if(mul[rt]!=1) {Downmul (RT<<1, mul[rt],m-l+1); Downmul (Rt<<1|1, mul[rt],r-m); MUL[RT]=1; }    if(add[rt]!=0) {Downadd (RT<<1, add[rt],m-l+1); Downadd (Rt<<1|1, add[rt],r-m); ADD[RT]=0; }}intop,c;voidModifyintRtintLintRintXinty) {    if(x<=l&&r<=y) {        if(op==1) Downadd (rt,c,r-l+1); Else if(op==2) Downmul (rt,c,r-l+1); ElseDownset (rt,c,r-l+1); return; }    intM= (l+r) >>1;    Down (RT,L,R); if(x<=m) Modify (rt<<1, L,m,x,y); if(y>m) Modify (rt<<1|1, m+1, R,x,y); Pushup (RT);}intAskintRtintLintRintXinty) {    if(x<=l&&r<=y)returnq[c-1][rt]; intans=0, m= (l+r) >>1;    Down (RT,L,R); if(x<=m) ans= (Ans+ask (rt<<1, l,m,x,y))%MoD; if(y>m) ans= (Ans+ask (rt<<1|1, m+1, r,x,y))%MoD; returnans;}intMain () {intn,m;  while(~SCANF ("%d%d",&n,&m)) {        if(!n&&!m) Break;  for(intI=0; i<=4*n;++i) {q[0][i]=q[1][i]=q[2][i]=add[i]=0; Mul[i]=1; Setval[i]=-1; }         while(m--){            intx, y; scanf ("%d%d%d%d",&op,&x,&y,&c); if(op<=3) Modify (1,1, N,x,y); Elseprintf"%d\n", Ask (1,1, n,x,y)); }    }    return 0;}
View Code

HDU4578 Transformation Segment Tree

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.