#P4215. 踩气球

踩气球

Description

Children’s Day has arrived, and SHUXK is forced to play a boring game with mm kids: there are nn boxes lined up from left to right, and the ii-th box contains aia_i balloons.

SHUXK will perform QQ operations. In each operation, he takes one unpopped balloon from some box, and the kids immediately pop it.

Each of the mm kids has specified an interval of boxes [li,ri][l_i, r_i]. If at any moment a kid finds that all balloons in their chosen interval [li,ri][l_i, r_i] have been popped, they become very happy (and will remain happy thereafter).

To live up to the expectations of the person who dumped this task on SHUXK, he asks you:

  • After each operation, how many kids are happy?

Input Format

The first line contains two positive integers nn and mm, the numbers of boxes and kids, respectively.

The second line contains nn positive integers aia_i (1ai1051 \le a_i \le 10^5), the number of balloons in each box.

Each of the following mm lines contains two positive integers li,ril_i, r_i (1lirin1 \le l_i \le r_i \le n), the interval specified by each kid.

The next line contains a positive integer QQ, the number of operations SHUXK performs.

Each of the following QQ lines contains a positive integer xx, indicating that this operation takes a balloon from the xx-th box. To enforce online queries, the input xx is encrypted.

Let the given positive integer be x^\hat{x}; then the real x=(x^+lastans1)modn+1x=(\hat{x}+\mathit{lastans}-1)\bmod n+1, where lastans\mathit{lastans} is the answer to the previous query. For the first query, lastans=0\mathit{lastans}=0.

Output Format

Output QQ lines. Each line should contain one integer, the answer to SHUXK’s question after a single operation. The answers must be in the same order as the input queries.

5 3
1 1 1 1 1
5 5
2 2
1 3
5 
4 
2 
5 
2 
3
0 
1 
1 
2 
3

Hint

Constraints and Conventions

For all data, 1n1051 \le n \le 10^5, 1m1051 \le m \le 10^5, 1Q1051 \le Q \le 10^5.

The testdata guarantees 1x^1091 \le \hat{x} \le 10^9, and that the xx-th box always has at least one unpopped balloon.

Translated by ChatGPT 5