Uestc_ Qiushi brother and Line tree UESTC Training for Data Structures<problem m>

Source: Internet
Author: User

M-Qiushi brother and line segment tree time limit:3000/1000ms (java/others) Memory limit:65535/65535kb (java/others)SubmitStatus

"Learn this bottomless, forward Mo." "Qiushi brother to the side play cell phone learning brother said."

Qiushi is a person who loves to learn, today he just learned the data structure of line segment tree.

In order to test their mastery degree, Qiushi eldest brother gave himself a problem, at the same time invited everyone to do.

Qiushi's subject asks you to maintain a sequence that supports two actions: one is to modify the value of an element, and one is to ask for an interval.

Input

The first line contains an integer n, which represents the length of the sequence.

The next line contains n integers ai, which represents the initial element of the sequence.

The next line contains an integer m, which represents the operand.

Next m line, each line is one of the following two actions:

1: indicates that the  value of the X element is changed to v2: an element that asks [l,R] This interval and  

1≤n,m,v,ai≤100000 , 1≤l≤r≤n.

Output

For each 2 l operation, the output is an integer representing the corresponding answer.

Sample Input and output
Sample Input Sample Output
31 2 332 1 21 1 52 1 2
37

Problem Solving Report

The subject ... Obviously there is no special skill, directly on the line tree can be solved, the only note is to use a long long.

#include <iostream>#include<cstring>typedefLong Longll;using namespacestd;Const intMAXN = 5e5 + the; ll TREE[MAXN];voidUpdata (intPosintVintOintLintR) {  if(L = =R) {Tree[o]=v; return; }  intMID = L + (r-l)/2; if(Pos <=mid) Updata (Pos,v,2*o,l,mid); ElseUpdata (pos,v,2*o+1, mid+1, R); Tree[o]= tree[2*o] + tree[2*o+1];} ll query (intQlintQrintOintLintR) {   if(QL <= l && R <=qr)returnTree[o]; ll Res=0; intMID = L + (r-l)/2; if(QL <=mid) Res+ = Query (QL,QR,2*o,l,mid); if(QR >mid) Res+ = Query (QL,QR,2*o+1, mid+1, R); returnRes;}intMainintargcChar*argv[]) {  intn,m; memset (Tree,0,sizeof(tree)); scanf ("%d",&N);  for(inti =1; I <= N; ++i) {inttemp; scanf ("%d",&temp); Updata (I,temp,1,1, N); } scanf ("%d",&m);  while(m--)   {          inti,j,k; scanf ("%d%d%d",&i,&j,&k); if(i = =1) Updata (J,k,1,1, N); Else{ll ans= Query (J,k,1,1, N); printf ("%lld\n", ans); }   }  return 0; }

Uestc_ Qiushi brother and Line tree UESTC Training for Data Structures<problem M>

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.