#P7908. [Ynoi2005] qwq

[Ynoi2005] qwq

Problem Description

Define the initial sequence as a sequence in which every number is 00.

Define one operation as increasing the value of every number in an interval of the sequence by 11, with the restriction that the length of this interval cannot exceed mm.

Given a sequence aa of length nn, where the ii-th number is aia_i.

You need to answer qq queries. In each query, you are given l,rl, r, and you need to output the minimum number of operations required to turn an initial sequence of length rl+1r-l+1 into the subarray [l,r][l, r] of aa (that is, the sequence al,al+1,,ara_l, a_{l+1}, \cdots, a_r).

Input Format

The first line contains three integers n,m,qn, m, q.

The second line contains nn integers, where the ii-th is aia_i.

The next qq lines each contain two integers l,rl, r.

Output Format

Output qq lines, each containing one integer, indicating the minimum number of operations.

5 4 1
1 1 2 1 1
1 5
2
10 3 3
4 8 1 2 9 7 4 1 3 5
1 10
3 8
5 5
22
10
9

Hint

"Sample 1 Explanation"

An initial sequence of length 55 is 00 00 00 00 00.

In the first operation, increase every number in the interval [1,3][1,3], that is, the 11st, 22nd, and 33rd numbers, by 11. After this operation, the sequence becomes 11 11 11 00 00.

In the second operation, increase every number in the interval [3,5][3,5], that is, the 33rd, 44th, and 55th numbers, by 11. After this operation, the sequence becomes 11 11 22 11 11.

"Constraints and Notes"

  • Subtask 1 (1 point): m=1m=1.
  • Subtask 2 (4 points): m=nm=n.
  • Subtask 3 (10 points): n,q300n,q\le300.
  • Subtask 4 (10 points): n,q5×103n,q\le5\times10^3.
  • Subtask 5 (15 points): m5m\le5.
  • Subtask 6 (15 points): m100m\le100.
  • Subtask 7 (20 points): n,q5×104n,q\le5\times10^4.
  • Subtask 8 (25 points): no special constraints.

For 100%100\% of the testdata, it is guaranteed that 1mn1051\le m\le n\le10^5, 1q1051\le q\le10^5, 0ai1090\le a_i\le10^9, and 1lrn1\le l\le r\le n.

Translated by ChatGPT 5