QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#10134. TEST_176

统计

You are given a sequence of length $n$, where the $i$-th element is $a_i$.

There are $q$ queries. Each query provides $x, l, r$, meaning you start with a number $x$ and traverse the sequence from index $l$ to $r$. For each position $i$ visited, you update $x$ by performing $x = \max(x, a_i - x)$. You need to output the final value of $x$ for each query.

Input

The first line contains two integers $n$ and $q$, representing the length of the sequence and the number of queries, respectively.

The second line contains $n$ integers, where the $i$-th integer is the value $a_i$ of the $i$-th element of the sequence.

The next $q$ lines each contain three integers $x, l, r$, as described in the problem statement.

Output

Output $q$ lines, each containing one integer, where the $i$-th line represents the answer to the $i$-th query.

Examples

Input 1

10 6
1 4 6 2 10 -3 1 0 13 4
2 1 10
0 5 10
5 1 10
0 4 8
-2 6 9
7 2 9

Output 1

7
10
8
8
11
7

Note

For the first query, the value of $x$ changes as follows: $2 (\text{initial}) \to 2 \to 2 \to 4 \to 4 \to 6 \to 6 \to 6 \to 6 \to 7 \to 7 (\text{final})$.

Constraints

For all data, it is guaranteed that $1 \leq n, q \leq 2 \times 10^5$, $1 \leq l \leq r \leq n$, and $0 \leq |x|, |a_i| \leq 10^{13}$.

Subtask ID $n, q \leq$ Special Properties Score
$1$ $1000$ None $8$
$2$ $80000$ $-500 \leq x, a_i \leq 500$ $16$
$3$ $2 \times 10^5$ $10^6 \leq x, a_i \leq 10^6$ and $l=1$ $25$
$4$ $2 \times 10^5$ $l=1$ $24$
$5$ $2 \times 10^5$ None $27$

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.