QOJ.ac

QOJ

Limite de temps : 5.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#12370. Pareto Frontier

Statistiques

Given $n$ pairs $(x_i, y_i)$, you need to answer $q$ queries. Each query provides a closed interval $[l, r]$. Please answer the number of integers $j$ that satisfy the following conditions:

  • $l \le j \le r$
  • There does not exist $k$ such that $l \le k \le r, k \neq j$, satisfying $x_k \ge x_j$ and $y_k \ge y_j$

Input

The first line contains two integers $n, q$ ($1 \le n, q \le 10^6$), representing the number of pairs and the number of queries, respectively.

The second line contains $n$ non-negative integers $x_1, x_2, \dots, x_n$ ($0 \le x_i \le 10^6$).

The third line contains $n$ non-negative integers $y_1, y_2, \dots, y_n$ ($0 \le y_i \le 10^6$).

The next $q$ lines each contain two integers $l, r$ ($1 \le l \le r \le n$), representing the query interval.

Output

For each query, output a single integer representing the answer on a new line.

Examples

Input 1

8 7
1 9 7 8 0 7 2 3
19 20 5 6 1 14 9 5
1 8
3 7
2 6
4 4
5 7
3 8
6 7

Output 1

1
2
1
1
1
2
1

Note

For query 1, the integers satisfying the conditions are $2$.

For query 2, the integers satisfying the conditions are $4, 6$.

For query 3, the integers satisfying the conditions are $2$.

For query 4, the integers satisfying the conditions are $4$.

For query 5, the integers satisfying the conditions are $6$.

For query 6, the integers satisfying the conditions are $4, 6$.

For query 7, the integers satisfying the conditions are $6$.

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.