Weirdtree

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

문제

Azusa, the witch of the highlands, has discovered a garden full of weird trees! Therefore, together with her friend, Laika, she decided to spend some time there taking care of the garden.

The garden can be viewed as a sequence of NN trees, where the trees are indexed from 11 to NN. Each tree has a certain non-negative integer height. Azusa will then spend her time according to a schedule containing QQ entries, which can be of several types:

  1. A tree cutting phase, characterised by three integers ll, rr, and kk. In this phase, Azusa will spend the next kk days cutting trees. Each day she finds the tallest tree whose index is between ll and rr and decreases its height by 11. In case there are several trees of this maximal height, she chooses the leftmost one. If the tallest tree has height 00, then nothing happens on that day.
  2. A magic phase, characterised by two integers ii and xx. In this phase, Azusa changes the tree with index ii so that it has height xx.
  3. A tree inspection phase, characterised by two integers ll and rr. In this phase, Azusa will find the sum of the heights of the trees with indices between ll and rr.

(Note that “between” is meant inclusively; e.g. 11, 22, 33, 44, 55 are “between” 11 and 55.)

Azusa is curious what the results of the tree inspection phases will be, and wants to know them without having to go through the entire schedule. Can you help her?

제한

  • 1N,Q300,0001 ≤ N, Q ≤ 300\\,000
  • It is guaranteed that the cut, magic and inspect functions will be called exactly QQ times in total.
  • 1iN1 ≤ i ≤ N
  • 0x,k,h\[i]1,000,000,0000 ≤ x, k, h\[i] ≤ 1\\,000\\,000\\,000
  • 1lrN1 ≤ l ≤ r ≤ N

힌트

In the first phase, after each of the 33 days of tree cutting, the heights of the trees are 1,2,2,1,2,31, 2, 2, 1, 2, 3; 1,2,2,1,2,21, 2, 2, 1, 2, 2; and 1,1,2,1,2,21, 1, 2, 1, 2, 2. The sum of these values is 99, which is the answer to the inspection in the second phase.

In the third phase, after each of the 33 days of tree cutting, the heights of the trees are 1,1,1,1,2,21, 1, 1, 1, 2, 2; 0,1,1,1,2,20, 1, 1, 1, 2, 2; and 0,0,1,1,2,20, 0, 1, 1, 2, 2. The sum of these values is 66, which is the answer to the inspection in the fourth phase.

In the fifth phase, after each of the 10001000 days of tree cutting, the heights of the trees are 0,0,0,1,2,20, 0, 0, 1, 2, 2. This is because a tree with height 00 cannot be cut. The sum of these values is 55, which is the answer to the inspection in the sixth phase.

In the seventh phase, the first tree is grown to height 10001000, giving us tree heights 1000,0,0,1,2,21000, 0, 0, 1, 2, 2. The sum of these values is 10051005, which is the answer to the inspection in the eighth phase.

In the ninth phase, each of the 999999 days of tree cutting reduces the height of the first tree by 11. This gives us tree heights 1,0,0,1,2,21, 0, 0, 1, 2, 2 at the end of the phase. The sum of the first five of these values is 44, which is the answer to the inspection in the tenth and final phase.