AtCoder Beginner Contest 242
G
Range Pairing Query
AtCoder
⌀ 1828
原题
← Ex→
翻译中…

Problem Statement

翻译中…

$N$ people numbered $1,2,\dots,N$ are standing in a row. Person $i$ wears Color $A_i$.

翻译中…

Answer $Q$ queries of the format below.

翻译中…
  • You are given integers $l$ and $r$. Considering only Person $l,l+1,\dots,r$, how many pairs of people wearing the same color can be formed at most?
翻译中…

Constraints

翻译中…
  • All values in input are integers.
  • $1 \le N \le 10^5$
  • $1 \le Q \le 10^6$
  • $1 \le A_i \le N$
  • $1 \le l \le r \le N$ in each query.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \dots A_N
Q
\mathrm{Query}_1
\mathrm{Query}_2
\vdots
\mathrm{Query}_Q

翻译中…

Here, $\mathrm{Query}_i$ represents the $i$-th query.

翻译中…

Each query is in the following format:

翻译中…

l r

翻译中…

Output

翻译中…

Print $Q$ lines. The $i$-th line should contain the answer for the $i$-th query as an integer. The use of fast input and output methods is recommended because of potentially large input and output.

翻译中…

样例

Input #1
10
1 2 3 2 3 1 3 1 2 3
6
6 10
5 8
3 6
4 4
1 6
1 10
Output #1
2
2
1
0
3
4
We have $A=(1,2,3,2,3,1,3,1,2,3)$. This input contains six queries. The first query is $(l, r) = (6, 10)$. By pairing Person $6, 8$ and paring Person $7, 10$, we can form two pairs of people wearing the same color. The second query is $(l, r) = (5, 8)$. By pairing Person $5, 7$ and paring Person $6, 8$, we can form two pairs of people wearing the same color. There can be a query where $l=r$.
题目信息
题号
abc242_g
时间限制
5 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。