CF 121 E Segment Tree Solution

Source: Internet
Author: User

Test instructions: The number of M operations for N is counted as the number of lucky numbers in the Count interval. Add a value to each number in the interval

Daniel on the internet is a tree-like array of line-segment trees can also be solved just a little hanging just learning line tree to strengthen the knowledge of the reserve and Code capability line Tree Single point update thank you for your advice

#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>UsingNamespace Std;int nM;int ans;int a[1000000];int tree[1000000];int b[50]={0,4,7,44,47,74,77,444,64u,474,477,744,747,774,777,4444,4447,4474,4477,4744,4747,4774,4777,7444,7447,7474,7477,7744,7747,7774,7777,};int F[1000000];voidPushup(int ID){Tree[ID]=tree[ID*2]+tree[ID*2+1];}voidUpdate(int ID,int Le,int RI,int x,int k){If(Le==ri){Tree[ID]+=k;Return;}int mid= (Le+ri)/2;If(x<=mid)Update(ID*2, le, midXK);ElseUpdate(ID*2+1, mid+1, RIXK);Pushup(ID);}IntQuery(int ID,int Le,int RI,int LL,int RR){If(LL<=le&&ri<=rr)Return tree[ID];int mid= (Le+ri)/2K=0;If(LL<=mid) K+=Query(ID*2, le, mid, LLRr);If(RR>mid) K+=Query(ID*2+1, mid+1, RI, LLRr);Return K;}IntMain(){int INM;scanf("%d%d", &n, &m);Memset(f,0,sizeof(f));For(I=1; I<=50; I+ +) F[b[I]]=1;For(I=1; I<=n; I++){scanf("%d", &a[I]);If(f[A[I]])Update(1,1N, I,1);}While(M--){Char Ch[100];scanf('%s ', &ch);int xYZ;scanf("%d%d", &x, &y);If(!strcmp(Ch,"Add")){scanf("%d", &z);For(int I=x; I<=y; I++){int k=0;If(f[A[I]]) K--; A[I]+=z;If(f[A[I]]) K++;If(k)Update(1,1,n,i,k);  } else Printf ( "%d\n  ",query1,1,n,x,y return 0;< Span class= "Sh-cbracket" >              

CF 121 E Segment Tree Solution

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.