Sereja and array-array operation or segment tree or tree-like array

Source: Internet
Author: User

codeforces-315bSereja and Array
Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %i64d &%i64u

Submit Status

Description

Sereja have got an array, consisting Of  n   Integers,  a 1,? A 2,?...,? A n . Sereja is a active boy, so he was now going to Complete  m  operations. Each operation would have one of the three forms:

  1. make  v i -th array element equal To  x i . In other words, perform the Assignment  a v i ? =? X i .
  2. Increase each of the array element by yi. In other words, perform n assignments ai? =? Ai? +? Yi(1?≤? I? ≤? n).
  3. Take a piece of paper and write out the qi-th array element. That is, the element aqi.

Help Sereja, complete all his operations.

Input

The first line contains integers n, m(1?≤? N,? M.≤?105). The second line contains n space-separated integers a1,? A2,?...,? An(1?≤? ) Ai? ≤?109) -the original array.

NextmLines describe operations, theI-th Line describes theI-th operation. The first number in theI-th Line is integer Ti (1?≤? ) Ti? ≤?3) That represents the operation type. If Ti? =?1 , then it was followed by and integers vi and xi ,(1?≤? ) Vi? ≤? N,? 1?≤? x i? ≤?109) . If Ti? =?2 , then it's followed by integer yi (1?≤? ) Yi? ≤?104) . And if Ti? =?3 , then it's followed by integer qi (1?≤? ) Qi? ≤? n) .

Output

For each third type operation print value aqi. Print the values in the order, with which the corresponding queries follow in the input.

Sample Input

Input
10 111 2 3 4 5 6 7 8 9 103 23 92 103 13 101 1 102 102 103 13 103 9
Output
291120304039
This topic everyone needs to think, do not see the topic on the line of the tree, to think there is no better way, the topic here gives three kinds of operations
It can be known that no one is operating on the interval, the only one is the whole array operation, and the effect on all the numbers.
So the code can be changed to the following:
/*author:2486memory:204 kbtime:93 mslanguage:gnu g++11 4.9.2result:acceptedvj runid:4206974real runid:12270208publi C:no yes*/#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;const int maxn= 1e5+5;int N,m,p,c,v,a[maxn];int Main () {    scanf ("%d%d", &n,&m);    for (int i=1; i<=n; i++) {        scanf ("%d", &a[i]);    }    int cnt=0;    while (m--) {        scanf ("%d%d", &p,&c);        if (p==1) {            scanf ("%d", &v);            a[c]=v-cnt;        } else if (p==2) {            cnt+=c;        } else {            printf ("%d\n", a[c]+cnt);        }    }    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Sereja and array-array operation or segment tree or tree-like array

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.