QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#14553. Sequences and Integer Pairs

Statistics

Given an integer sequence $A_1, A_2, \dots, A_n$ of length $n$, and $q$ queries, each query provides two integers $x$ and $y$. Find the number of integer pairs $(i, j)$ such that $1 \le i < j \le n$, $A_i = x$, and $A_j = y$.

Input

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

The second line contains $n$ integers $A_1, A_2, \dots, A_n$ ($1 \le A_i \le 10^9$), representing the given sequence.

The next $q$ lines each contain two integers $x, y$ ($1 \le x, y \le 10^9$), representing a query.

Output

Output $q$ lines, each containing one integer, representing the number of pairs $(i, j)$ such that $1 \le i < j \le n$, $A_i = x$, and $A_j = y$.

Examples

Input 1

11 3
3 1 4 1 5 9 2 6 5 3 5
3 5
1 3
4 8

Output 1

4
2
0

Note

For the first query, the 4 pairs satisfying the conditions are $(1, 5), (1, 9), (1, 11), (10, 11)$.

For the second query, the 2 pairs satisfying the conditions are $(2, 10), (4, 10)$.

For the third query, there are no pairs satisfying the conditions.

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.