Hard work of volunteers
Limits: 3 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Thousands of volunteers daily help Ukrainian soldiers perform their duties.
Zenyk is one such volunteer. He is engaged in transporting parcels along the front line. Frontline positions are numbered with integers from \(0\) to \(10^9\). Zenyk has already planned his route for today. Currently, he is at position \(0\), then he will go to position \(x_1\), then from there to position \(x_2\) and so on, until he finishes his work for today at position \(x_n\). Zenyk calls positions \(x_1\), \(x_2\), …, \(x_n\) key positions, but when traveling from one key position to another, he also visits all intermediate positions between them.
Zenyk knows about \(m\) parcels that need to be transported. The \(i\)-th parcel needs to be delivered from position \(a_i\) to position \(b_i\). Visiting a position, Zenyk picks up all parcels that need to be sent from this position and delivers all parcels he has already picked up that are addressed here. I wonder how many parcels Zenyk will be able to deliver today?
Input
The first line contains two integers separated by a space — \(n\) and \(m\) — the number of key positions and the number of parcels Zenyk knows about.
The second line contains \(n\) integers separated by a space — the numbers of key positions that Zenyk will visit.
The next \(m\) lines each contain two integers — \(a_i\) and \(b_i\) — where the \(i\)-th parcel needs to be delivered from and to.
Output
A single number — the number of parcels that Zenyk will deliver.
Constraints
\(1 \le n, m \le 10^5\),
\(0 \le x_i, a_i, b_i \le 10^9\), \(a_i \ne b_i\).
Problem evaluation consists of the following blocks:
1 point — example from the statement,
4 points — block of tests in which \(n, m, x_i, a_i, b_i \le 100\).
10 points — block of tests in which \(n, m \le 1000\).
10 points — block of tests without additional constraints.
You will receive points for a block only if you give the correct answer to all tests in the block.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 3 3 7 4 7 2 4 7 5 6 3 | 2 |
Notes
Initially, Zenyk will pick up the first parcel at position 2. At position 4, Zenyk will deliver the first parcel. Next, Zenyk will pick up the third and second parcels at positions 6 and 7, respectively. Heading to the next key position (numbered 4), Zenyk will be able to deliver the second parcel at position 5. On the way from position 4 to 7, there are no more parcels to pick up or deliver. Zenyk does not have an opportunity to deliver the third parcel.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|