#P15832. [JOI Open 2015] Sterilizing Spray

[JOI Open 2015] Sterilizing Spray

Description

Mr. JOI is working at the IOI Pharmaceutical Co., Ltd. In this company, researchers are busy with experimental work to develop new sterilization sprays.

In this company, the strength of a sterilization spray is defined as follows: when we use a spray of strength xx once for a culture plate with yy bacteria, the number of bacteria on it becomes y/x\lfloor y/x \rfloor, which is the integer obtained from y/xy/x by rounding off fractions. Now, a new spray of strength KK is developed. In order to test the performance of this spray, they plan to experiment on it. They use NN culture plates numbered 1,,N1, \dots, N. At the beginning, there are CiC_i bacteria on the culture plate ii. In the experiment, they implement QQ operations in sequence. Each operation is one of the following:

  • Operation 1: Choose a culture plate aa and an integer bb, and adjust the number of bacteria on the culture plate aa. After this operation, the number of bacteria on the culture plate aa becomes bb.
  • Operation 2: Choose two integers l,rl, r with 1lrN1 \leq l \leq r \leq N. Spray once for each of the culture plates l,l+1,,r1,rl, l+1, \dots, r-1, r.
  • Operation 3: Choose two integers l,rl, r with 1lrN1 \leq l \leq r \leq N. Calculate the sum of the numbers of bacteria on the culture plates l,l+1,,r1,rl, l+1, \dots, r-1, r, and record it.

Mr. JOI is curious about the results of the experiment assuming that the new spray works as expected. Since you are a good programmer, he asks you to predict the results of the experiment.

Write a program which determines the numbers recorded by the operation 3s in the experiment.

Task

Given the strength of the spray and the information on the operations in the experiment, write a program which determines the numbers recorded by the operation 3s.

Input Format

Read the following data from the standard input.

  • The first line of input contains three space separated integers N,Q,KN, Q, K. This means the strength of the spray is KK, the number of culture plates is NN, and the number of operations in the experiment is QQ.
  • The ii-th line (1iN1 \leq i \leq N) of the following NN lines contains an integer CiC_i. This means there are CiC_i bacteria on the culture plate ii at the beginning of the experiment.
  • The ii-th line (1iQ1 \leq i \leq Q) of the following QQ lines contains three space separated integers Si,Ti,UiS_i, T_i, U_i. They indicate information on the ii-th operation in the experiment.
    • When Si=1S_i = 1, they mean the operation 1 with a=Ti,b=Uia = T_i, b = U_i.
    • When Si=2S_i = 2, they mean the operation 2 with l=Ti,r=Uil = T_i, r = U_i.
    • When Si=3S_i = 3, they mean the operation 3 with l=Ti,r=Uil = T_i, r = U_i.

Output Format

Write the numbers recorded by the operation 3s in the experiment. The number of lines in the output is equal to the number of the operation 3s implemented in the experiment.

5 10 3
1
2
8
1
3
1 2 5
2 3 5
3 2 5
2 1 4
1 3 2
3 3 5
1 2 4
2 1 2
1 1 4
3 1 5
8
3
8
15 10 3
25
87
32
89
24
99
57
88
10
57
65
42
66
98
13
3 9 12
1 7 15
3 2 9
2 1 14
3 10 13
1 10 6
2 14 14
1 7 96
3 14 15
3 10 12
174
444
76
23
41

Hint

Sample 1 Explanation

  • At the beginning of the experiment, the numbers of bacteria on the culture plates are 1 2 8 1 31\ 2\ 8\ 1\ 3.
  • Adjust the number of bacteria on the culture plate 2 to 5. After this operation, the numbers of bacteria on the culture plates are 1 5 8 1 31\ 5\ 8\ 1\ 3.
  • The numbers of bacteria on the culture plates 3,4,5 are divided by 3 and rounded off fractions. After this operation, the numbers of bacteria on the culture plates are 1 5 2 0 11\ 5\ 2\ 0\ 1.
  • Since the sum of the numbers of bacteria on the culture plates 2,3,4,5 is 8, write 8 to the output.
  • The numbers of bacteria on the culture plates 1,2,3,4 are divided by 3 and rounded off fractions. After this operation, the numbers of bacteria on the culture plates are 0 1 0 0 10\ 1\ 0\ 0\ 1.
  • Adjust the number of bacteria on the culture plate 3 to 2. After this operation, the numbers of bacteria on the culture plates are 0 1 2 0 10\ 1\ 2\ 0\ 1.
  • Since the sum of the numbers of bacteria on the culture plates 3,4,5 is 3, write 3 to the output.
  • Adjust the number of bacteria on the culture plate 2 to 4. After this operation, the numbers of bacteria on the culture plates are 0 4 2 0 10\ 4\ 2\ 0\ 1.
  • The numbers of bacteria on the culture plates 1,2 are divided by 3 and rounded off fractions. After this operation, the numbers of bacteria on the culture plates are 0 1 2 0 10\ 1\ 2\ 0\ 1.
  • Adjust the number of bacteria on the culture plate 1 to 4. After this operation, the numbers of bacteria on the culture plates are 4 1 2 0 14\ 1\ 2\ 0\ 1.
  • Since the sum of the numbers of bacteria on the culture plates 1,2,3,4,5 is 8, write 8 to the output.

Constraints

All input data satisfy the following conditions.

  • 1N1000001 \leq N \leq 100\,000.
  • 1Q1000001 \leq Q \leq 100\,000.
  • 1K101 \leq K \leq 10.
  • 0Ci10000000000 \leq C_i \leq 1\,000\,000\,000 (1iN1 \leq i \leq N).
  • 1Si31 \leq S_i \leq 3 (1iQ1 \leq i \leq Q).
  • When Si=1S_i = 1 is satisfied, 1TiN1 \leq T_i \leq N and 0Ui10000000000 \leq U_i \leq 1\,000\,000\,000 (1iQ1 \leq i \leq Q).
  • When Si=2,3S_i = 2,3 is satisfied, 1TiUiN1 \leq T_i \leq U_i \leq N (1iQ1 \leq i \leq Q).

Subtask

Subtask 1 [5 points]

  • 1N30001 \leq N \leq 3\,000.
  • 1Q30001 \leq Q \leq 3\,000.

Subtask 2 [10 points]

  • K=1K = 1.

Subtask 3 [10 points]

  • Ci1C_i \leq 1 (1iN1 \leq i \leq N).
  • When Si=1S_i = 1 is satisfied, Ui1U_i \leq 1 (1iQ1 \leq i \leq Q).

Subtask 4-10 [75 points]

There are no additional constraints.