Interval modification Point Query HDU1556

Source: Internet
Author: User

1#include <iostream>2#include <cstdio>3 4 using namespacestd;5 6 structNode7 {8     intL,r;9     intv;Ten     intLZ; One}bn[400000]; A  - voidBuildintKintLintR) - { theBn[k].l=l; -Bn[k].r=R; -bn[k].lz=0; -     if(bn[k].l==BN[K].R) +     { -bn[k].v=0; +         return ; A     } at     intlk=k*2; -     intrk=lk+1; -     intMid= (L+R)/2; - build (Lk,l,mid); -Build (rk,mid+1, R); -bn[k].v=0; in } -  to voidPushintk) + { -     intlk=k*2; the     intrk=lk+1; *bn[lk].v+=Bn[k].lz; $bn[rk].v+=Bn[k].lz;Panax Notoginsengbn[lk].lz+=Bn[k].lz; -bn[rk].lz+=Bn[k].lz; thebn[k].lz=0; + } A  the voidChangeintKintLintR) + { -     if(bn[k].l==l&&bn[k].r==R) $     { $bn[k].lz++; -bn[k].v=bn[k].lz* (bn[k].r-bn[k].l+1); -         return ; the     } -     if(BN[K].LZ)Wuyi push (k); the     intlk=k*2; -     intrk=lk+1; Wu     if(bn[lk].r>=R) - Change (lk,l,r); About     Else if(bn[rk].l<=l) $ Change (rk,l,r); -     Else -     { - Change (LK,L,BN[LK].R); A Change (rk,bn[rk].l,r); +     } thebn[k].v=bn[rk].v+bn[lk].v; - } $  the intans; the voidSearchintKinti) the { the     if(bn[k].l==i&&bn[k].r==i) -     { inans=bn[k].v; the         return ; the     } About     if(BN[K].LZ) the push (k); the     intlk=k*2; the     intrk=lk+1; +     if(bn[lk].r>=i) - search (lk,i); the     Else if(bn[rk].l<=i)Bayi search (rk,i); thebn[k].v=bn[rk].v+bn[lk].v; the } -  - intMain () the { the     intN; the      while(cin>>n&&N) the     { -         intb; theBuild1,1, n); the          for(intI=1; i<=n;i++) the         {94scanf"%d%d",&a,&b); theChange1, A, b); the         } theSearch1,1);98cout<<ans; About          for(intI=2; i<=n;i++) -         {101Search1, i);102cout<<" "<<ans;103         }104cout<<Endl; the     }106     return 0;107}
View Code

This is normal line segment tree practice

1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 7 intan[100010];8 intans[100010];9 Ten intMain () One { A     intN; -      while(cin>>n&&N) -     { theMemset (AN,0,sizeof(an)); -memset (ans,0,sizeof(ans)); -         intb; -          for(intI=1; i<=n;i++) +         { -scanf"%d%d",&a,&b); +an[a]+=1; Aan[b+1]+=-1; at         } -          for(intI=1; i<=n;i++) -         { -ans[i]=ans[i-1]+An[i]; -         } -cout<<ans[1]; in          for(intI=2; i<=n;i++) -         { tocout<<" "<<Ans[i]; +         } -cout<<Endl; the     } *     return 0; $}
View Code

Simple method with a time complexity of n

Interval modification Point Query HDU1556

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.