1D Spreadsheet

아직 제출이 없습니다시간 제한10초메모리 제한512 MB

문제

You've got a marvellous opportunity to work as an intern for a huge software company over summer. The project you are assigned to is a brand new, cutting-edge application --- 1D spreadsheet.

A 1D spreadsheet is an array of nn cells numbered from 1 to nn. The cell ii may contain either an integer a_ia\_i or a link to some other cell l_il\_i (in which case we will say that the cell ii is linked to the cell l_il\_i). Cyclic link dependencies are not allowed, that is, at any moment, there is no sequence of cells i_1i\_1, i_2i\_2, \ldots, i_ki\_k such that the cell i_1i\_1 is linked to the cell i_2i\_2, \ldots, and the cell i_ki\_k is linked to the cell i_1i\_1.

Every cell can be evaluated to produce its value, which is defined as follows: if the cell ii contains a number a_ia\_i then value(i)=a_ivalue(i) = a\_i, otherwise value(i)=value(l_i)value(i) = value(l\_i); that is, to evaluate a cell one must follow a chain of links that starts at the cell until he arrives at a cell that contains a number. As cyclic dependencies are disallowed, at any moment, value(i)value(i) can be determined unambiguously for every cell ii.

Your colleague Bill has just finished developing a new feature for the spreadsheet --- range value summation. With this feature enabled, user may ask queries of sort "find _i=lrvalue(i)\sum\_{i = l}^r value(i)'' as well as change the contents of cells. However, after some performance testing it turned out that Bill's implementation is quite slow. Your task is to optimize this feature. Write a program that processes a sequence of queries to 1D spreadsheet.

입력

The first line of input contains two space-separated integers nn and qq (1n,q21051 \leq n, q \leq 2 \cdot 10^5) --- the number of cells in the spreadsheet and the number of queries to process, respectively.

The second line contains nn space-separated integers a_1a\_1, \ldots, a_na\_n (104a_i104-10^4 \leq a\_i \leq 10^4) --- the initial values of cells. Initially, no cell contains a link.

The next qq lines contain descriptions of queries according to the following format:

  • "set ii xx" --- assign the cell ii to contain the number xx (104x104-10^4 \leq x \leq 10^4
  • "link ii jj" --- assign the cell ii to contain link to the cell jj.
  • "sum ll rr" --- find _i=lrvalue(i)\sum\_{i = l}^{r} value(i).

It is guaranteed that cyclic dependencies will not occur at any point of time.

출력

Output the answers for "sum ll rr" queries in the same order as in the input, one per line.