hiho1080 more sophisticated buying and selling house posture

Source: Internet
Author: User

Topic Links:

hihocoder1080




Solution:

There are two actions for interval modification in the topic:

0 interval All points increased V

1 All points in the interval are changed to V


Easy to think of should use to two lazy mark a record to replace a record increase or decrease

But there's a sequential problem here, and there's a strategy for lazy tagging to take into account:

If a replacement tag appears, you should overwrite the increment and decrement mark

If multiple increment and decrement markers appear in the same interval, the markers need to be superimposed



Code:

#include <iostream> #include <cstdio> #include <cstring> #define Lson l,m,rt<<1#define Rson m+1, R,rt<<1|1#define maxn 100050using namespace Std;int w[maxn<<2];int tag[maxn<<2][2]= {0};void push_up (int RT) {w[rt]=w[rt<<1]+w[rt<<1|1];} void Push_down (int rt,int len) {if (tag[rt][1])//replace tag {tag[rt<<1][1]=tag[rt<<1|1][1        ]=TAG[RT][1];      tag[rt<<1][0]=tag[rt<<1|1][0]=0;        0 w[rt<<1]= (len-(len>>1)) *tag[rt][1] for the increase or decrease of child nodes;        w[rt<<1|1]= (len>>1) *tag[rt][1];    tag[rt][1]=0;         } if (Tag[rt][0])//increment/decrement tag {tag[rt<<1][0]+=tag[rt][0];         Overlay is + = Not =!!!       tag[rt<<1|1][0]+=tag[rt][0];        Overlay w[rt<<1]+= (len-(len>>1)) *tag[rt][0];        w[rt<<1|1]+= (len>>1) *tag[rt][0];    tag[rt][0]=0;    }}void Build (int l,int R,int RT) {if (l==r) scanf ("%d", &w[rt]); Else    {int m= (L+R) >>1;        Build (Lson);        Build (Rson);    PUSH_UP (RT);            }}void Update (int op,int l,int r,int v,int l,int r,int RT) {if (l<=l&&r>=r) {if (OP) {            w[rt]= (r-l+1) *v;            Tag[rt][1]=v;             tag[rt][0]=0;         Add or subtract Mark 0} else {w[rt]+= (r-l+1) *v;        Overlay Tag[rt][0]+=v;    } return;    } push_down (rt,r-l+1);    int m= (L+R) >>1;    if (l<=m) update (Op,l,r,v,lson);    if (r>m) update (Op,l,r,v,rson);  PUSH_UP (RT);}    int main () {int n,q,op,l,r,v;    scanf ("%d%d", &n,&q);    Build (0,n,1);        while (q--) {scanf ("%d%d%d%d", &op,&l,&r,&v);        Update (op,l,r,v,0,n,1);    printf ("%d\n", w[1]); } return 0;}


hiho1080 more sophisticated buying and selling house posture

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.