QOJ.ac

QOJ

时间限制: 3 s 内存限制: 512 MB 总分: 100

#11063. TEST_90

统计

Given a sequence $a_1, \dots, a_n$ of length $n$.

There are $m$ queries. Each query provides $l$ and $r$, and you need to find the number of subsegments $[i, j]$ such that $l \le i \le j \le r$, where the number of distinct elements appearing in the subsegment $[i, j]$ is odd.

Input

The first line contains an integer $n$.

The next line contains $n$ integers representing the sequence $a_1, \dots, a_n$.

The next line contains an integer $m$.

The next $m$ lines each contain two integers $l$ and $r$ representing a query.

Output

For each query, output a single line containing an integer representing the answer.

Examples

Input 1

5
2 3 5 1 5
5
2 3
1 1
1 3
2 5
2 4

Output 1

2
1
4
6
4

Input 2

10
2 8 5 1 10 5 9 9 3 5
10
6 8
1 2
3 5
5 7
1 7
3 9
4 9
1 4
3 7
2 5

Output 2

4
2
4
4
16
16
12
6
9
6

Subtasks

Idea: nzhtl1477, Solution: ccz181078, Code: ccz181078, Data: ccz181078

For $25\%$ of the data, $1 \le n, m \le 10^2$.

For $50\%$ of the data, $1 \le n, m \le 10^4$.

For another $25\%$ of the data, the number of distinct elements appearing in the sequence does not exceed $100$.

For $100\%$ of the data, $1 \le n \le 10^6$, $1 \le m \le 10^6$, $1 \le a_i \le n$.

For each query, $1 \le l \le r \le n$.

All values above are integers.

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.