Under construction

Still being built. Things may change

Pumba's Water Reservoir

Time limit4sMemory limit1024 MB

Summary
Pumba adds water to ranges of basins, each capped at m liters, and must answer range sum queries over k days.
Level

Medium6 of 10

Topics
Divide and conquer, Array, Implementation
Solved
No attempts yet

Problem

Pumba is very thrifty. Worried about a possible drought, he decided to stock up on water. Pumba has nn numbered wooden basins. The volume of each basin is mm liters. Pumba will stock water over kk days. On each day, Pumba performs exactly one of the following actions:

  • Adds cic_i liters of water to every basin with numbers from lil_i to rir_i inclusive. If a basin cannot hold cic_i liters, Pumba fills it completely.
  • Asks Timon for the total amount of water in the basins with numbers from lil_i to rir_i inclusive.

Timon is very lazy, so he has assigned you to answer Pumba's questions. Before stocking begins, the ii-th basin already contains aia_i liters of water.

Input

The first line contains three integers nn, mm, kk: the number of basins, the volume of one basin, and the number of days Pumba will stock water (1≤n≤2000001 \le n \le 200000, 1≤m≤1091 \le m \le 10^9, 1≤k≤2000001 \le k \le 200000).

The second line contains nn integers aia_i, the amount of water in each basin before stocking (0≤ai≤m0 \le a_i \le m).

Each of the next kk lines describes Pumba's action on that day. If on day ii Pumba adds water, the first number of the line is 1, followed by three integers lil_i, rir_i, cic_i (1≤li≤ri≤n1 \le l_i \le r_i \le n, 1≤ci≤1091 \le c_i \le 10^9). If on day ii Pumba asks for the total, the first number of the line is 2, followed by two integers lil_i and rir_i (1≤li≤ri≤n1 \le l_i \le r_i \le n).

Output

For each of Pumba's questions, print the answer on its own line, in the order the questions are given.

Examples1

  1. Example 1

    Input
    3 3 7
    1 2 1
    1 1 2 1
    2 1 3
    1 2 3 1
    2 1 3
    2 1 1
    2 2 2
    2 3 3
    
    Expected output
    6
    7
    2
    3
    2