Segment update of HDU 1698 Line Segment

Source: Internet
Author: User

Segment update of HDU 1698 Line Segment

Question: Give You T group data, N numbers in each group, initially 1, M operations. Each operation updates the values from a to B to ask the sum of n numbers.

Idea: a simple line segment is updated and requires the use of the lazy mark. To put it bluntly, the lazy mark is used to update it, otherwise it will be put there.

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include using namespace std;const int inf=0x3f3f3f3f;const int maxn=1e5+10;typedef long long ll;#define mm(a) memset(a,0,sizeof(a))int num[maxn<<2],num1[maxn<<2];void pushup(int node){    num[node]=num[node<<1]+num[node<<1|1];}void pushdown(int node,int node1){    if(num1[node]){        int t=num1[node];        num1[node<<1]=t;        num1[node<<1|1]=t;        num[node<<1]=(node1-(node1>>1))*t;        num[node<<1|1]=(node1>>1)*t;        num1[node]=0;    }}void buildtree(int le,int ri,int node){    if(le==ri){        num[node]=1;        return ;    }    int t=(le+ri)>>1;    buildtree(le,t,node<<1);    buildtree(t+1,ri,node<<1|1);    pushup(node);}void update(int l,int r,int add,int le,int ri,int node){    if(l<=le&&ri<=r){        num1[node]=add;        num[node]=add*(ri-le+1);        return ;    }    pushdown(node,ri-le+1);    int t=(le+ri)>>1;    if(l<=t) update(l,r,add,le,t,node<<1);    if(r>t) update(l,r,add,t+1,ri,node<<1|1);    pushup(node);}int main(){    int T,t=1,n,m;    scanf("%d",&T);    while(T--){        mm(num1);        scanf("%d%d",&n,&m);        int a,b,c;        buildtree(1,n,1);        while(m--){            scanf("%d%d%d",&a,&b,&c);            update(a,b,c,1,n,1);//            for(int i=1;i<=4*n;i++)//                cout<
     
    
   
  
 

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.