#P8182. 「EZEC-11」雪的魔法

    ID: 8937 远端评测题 1200ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP2022洛谷原创O2优化分治线性规划分块整体二分洛谷月赛

「EZEC-11」雪的魔法

Background

Muxii is a snow mage. As long as he waves his wand and chants a mysterious spell, snowflakes will fall from the sky and slowly build up a thick layer of snow on the ground. Because Muxii's magic is so powerful, God appointed Muxii to control all the snow in the world.

One day, God gave Muxii a task: he needs to make it snow on a piece of ground of length nn. The snow depth at position ii must reach aia_i (ai0a_i \ge 0; “reach aia_i” means it can be neither less than nor greater than aia_i). However, what God does not know is that Muxii's ability is limited: each time he casts a spell, he can only make it snow for 1 second on an interval of length m\le m, increasing the snow depth in that interval by 11. Since the task is urgent, Muxii wants to know: to complete the task for some interval, how many spells does he need to cast at minimum?

Problem Description

Define the initial sequence as a sequence where every number is 00.

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

You are 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. You need to output the minimum number of operations required to transform an initial sequence of length rl+1r - l + 1 into [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 one is aia_i.

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

Output Format

Output qq lines, each containing one integer, 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.

The first operation increases every number in interval [1,3][1, 3], i.e. the 11st, 22nd, and 33rd numbers, by 11. After this operation, the sequence becomes 11 11 11 00 00.

The second operation increases every number in interval [3,5][3, 5], i.e. 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 \le 300.
  • Subtask 4 (10 points): n,q5×103n, q \le 5 \times 10^3.
  • Subtask 5 (15 points): m5m \le 5.
  • Subtask 6 (15 points): m100m \le 100.
  • Subtask 7 (20 points): n,q5×104n, q \le 5 \times 10^4.
  • Subtask 8 (25 points): No special constraints.

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

Translated by ChatGPT 5