A system of balance scales

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

문제

A complicated system of balance scales and weights is set out on the floor. Each set of balance scales consist of a stand, a beam and two cups. The beam is not fixed and rests on the stand with a single point in such a manner that it can rotate freely around it in the vertical plane. Precise bearing point selection allows a state of nonstable equilibrium in horizontal position. Cups are attached to the beam ends, and they usually hold objects whose weights are to be compared. The distance from the bearing point to the cup is called a shoulder. The rule states that upon reaching the equilibrium shoulders correlate in the same way as do the weights of the objects in the cups. The system of balance scales and weights works in the following way: Each of the cups of all scales holds either a balance weight or another pair of balance scales. There is strictly one pair of balance scales standing directly on the floor, with all other scales standing in cups of other scales. The weights of all balance weights are known, and the weight of the scales themselves are negligibly small compared to the balance weights. All scales are always in the state of equilibrium owing to correct choice of bearing points. The sizes of balance weights, cups and stands are also negligibly small compared to the length of beams.

Process a sequence of queries of two types.

  1. Change the weight of a given balance weight.
  2. Learn the position of the bearing point of a given pair of scales.

After each weight change of any balance weight equilibrium must be restored in all scales in the system, with some of its bearing points shifting in the process.

입력

The first line contains two integers: NN --- the number of scales in the system(1N51041 \le N \le 5 \cdot 10^4) and KK --- the number of queries (1K1051 \le K \le 10^5).

All scales are numbered with integers beginning from one and up. Scales with the number 11 stand on the floor. All balance weights are also numbered with integers beginning from one and up.

The second line contains (N+1)(N+1) integers: the tt-th of these numbers W_tW\_t defines the initial weight of the balance weight with the number tt (1W_t1091 \le W\_t \le 10^9).

The following NN line describe the scales. The ii-th of these lines contains three integers: S_iS\_i --- length of the beam of the ii-th pair of scales (1L_i1041 \le L\_i \le 10^4), L_iL\_i --- number of the scales standing in the left cup of the ii-th scales and R_iR\_i --- number of the scales standing in the right cup of the ii-th scales. If the left cup is occupied by scales, then i<L_iNi < L\_i \le N, if it is occupied by a balance weight, then L_iL\_i equals the number of the balance weight with a <<minus>> sign, with 1L_iN+11 \le -L\_i \le N+1. Similarly, R_iR\_i defines either the number of the standing scales (i<R_iNi < R\_i \le N) or the number of the balance weight with a <<minus>> (1R_iN+11 \le -R\_i \le N+1).

This is followed by KK lines, with every jj-th line containing a single query. The query description begins with an integer t_jt\_j, defining the query type (1t_j21 \le t\_j \le 2). If t_j=1t\_j = 1, it is followed by two integers: k_jk\_j --- number of the balance weight with its weight being changed (1k_jN+11 \le k\_j \le N+1), V_jV\_j --- new weight of the balance weight(1V_j1091 \le V\_j \le 10^9). If t_j=2t\_j = 2, it is followed by a single integer k_jk\_j --- the number of scales for which the position of its bearing point must be found (1k_jN1 \le k\_j \le N). There are no other types of queries.

출력

For each query to define the bearing point a single integer must be printed: the distance from the left cup of the scales to the bearing point. Answers must be produced in the order of occurence of the corresponding queries in the input data. The absolute or relative error of each answer should be less than or equal 101310^{-13}.

힌트

Initial state of the system from the second sample: