QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#901. Stone Moving

Statistics

There are $n$ stones arranged in a row, with the $i$-th stone initially at position $a_i$.

fpdqwq performs $q$ operations on these stones. In the $i$-th operation, all stones at positions $p$ satisfying $p \pmod{x_i} = y_i$ are moved by one position in the direction $z_i$ (where $z_i=1$ denotes moving in the positive direction, and $z_i=-1$ denotes moving in the negative direction).

After all operations are completed, fpdqwq does not know where the stones have ended up, so they ask you how many stones remain in the position range $[l, r]$ (i.e., positions $l, l+1, \dots, r$).

Input

The first line contains two positive integers $n$ and $q$, separated by a space, representing the number of stones and the number of operations, respectively.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$, representing the initial positions of all stones.

The next $q$ lines each contain three integers $x_i, y_i, z_i$, representing an operation.

The last line contains two positive integers $l$ and $r$, representing the queried range.

Output

Output a single integer representing the answer.

Examples

Input 1

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

Output 1

3

Note 1

The first operation moves all stones. The second operation moves the 2nd and 4th stones. The last operation does not move any stones. Finally, the 1st, 3rd, and 5th stones are located within $[0, 5]$.

Constraints

For $24\%$ of the data: $n \leq 100, q \leq 100$

For $60\%$ of the data: $n \leq 5000, q \leq 5000$

For $97\%$ of the data: $n \leq 100000, q \leq 100000$

For $100\%$ of the data: $1 \leq n \leq 500000, 0 \leq q \leq 500000, 0 \leq a_i \leq 10^9, 0 \leq y_i < x_i \leq 10^9, 0 \leq l \leq r \leq 10^9, |z_i|=1$

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.