QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 500 MB 満点: 100

#7480. Love for Data Structures

統計

Nauuo is a girl who loves programming. One day, she was working on a problem that required calculating the sum of some numbers modulo $p$.

She wrote the following code and received a WA (Wrong Answer) verdict.

She quickly discovered the bug—the ModAdd function only works correctly for numbers in the range $[0, p)$, but the numbers in this problem might fall outside this range. She is curious about the result of this incorrect function, so she wants to know its output.

However, the original code runs too slowly, so she has come to you for help.

Given an array $a_1, a_2, \dots, a_n$ and a number $p$, there are $m$ queries. Each query provides two numbers $l$ and $r$, and you need to calculate the return value of the function Sum(a, l, r, p). The definition of the Sum function is provided in the pseudocode above.

Note that in the code above, integers will not overflow.

Input

The first line contains three integers $n$, $m$, and $p$, representing the length of the array, the number of queries, and the modulus, respectively. Note that the modulus is only used in ModAdd.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$, representing the given array.

The next $m$ lines each contain two integers $l$ and $r$, for which you need to calculate Sum(a, l, r, p).

Output

Output $m$ integers in order, one per line, representing the answers to the queries.

Examples

Input 1

4 5 6
7 2 -3 17
2 3
1 3
1 2
2 4
4 4

Output 1

-1
0
3
10
11

Note

Idea: rushcheyo, Solution: ccz181078, Code: rushcheyo & ccz181078, Data: rushcheyo

For $100\%$ of the data, $1 \le n \le 10^6$, $1 \le m \le 2 \times 10^5$, $1 \le p \le 10^9$, $-10^9 \le a_i \le 10^9$, $1 \le l \le r \le n$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.