This page is still under construction.

Parts of this page are still being built. What you see may change.

Operations

Time limit1sMemory limit128 MB

Summary
Maintain an array of values below k under interval cyclic increments and answer interval sums.
Level

Medium6 of 10

Topics
Segment tree
Solved
No attempts yet

Problem

You are given a sequence of nn integers a1,a2,…,ana_1, a_2, \dots, a_n, where every element lies in the range [0,k−1][0, k-1]. Perform mm operations of the following two kinds on this sequence.

  1. Report the range sum ac+ac+1+⋯+ada_c + a_{c+1} + \dots + a_d.
  2. Replace every aia_i with c≤i≤dc \le i \le d by (ai+l) mod k(a_i + l) \bmod k.

Input

The first line contains three integers nn, kk, and mm (1≤n≤1000001 \le n \le 100000, 1≤k≤101 \le k \le 10, 1≤m≤1000001 \le m \le 100000). The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n describing the sequence (0≤ai≤k−10 \le a_i \le k-1).

Each of the next mm lines describes one operation. Each line begins with an integer zz giving the operation type. If z=1z = 1, it is a range-sum query and is followed by two integers cc and dd. If z=2z = 2, it is a range-update operation and is followed by three integers cc, dd, and ll (1≤c≤d≤n1 \le c \le d \le n, 0≤l≤k−10 \le l \le k-1).

Output

For each range-sum operation, print the computed result on its own line.

Examples1

  1. Example 1

    Input
    4 3 6
    0 0 0 0
    2 1 1 1
    1 1 4
    2 1 2 1
    1 1 4
    2 1 3 1
    1 1 4
    
    Expected output
    1
    3
    3