P10822 [EC Final 2020] Prof. Pang's sequence

Description

Prof. Pang is given a fixed sequence $a_1, \ldots, a_n$ and $m$ queries. Each query is specified by two integers $l$ and $r$ satisfying $1\le l\le r\le n$. For each query, you should answer the number of pairs of integers $(i, j)$ such that $l\le i\le j\le r$ and the number of distinct integers in $a_i, \ldots, a_j$ is odd.

Input Format

The first line contains a single integer $n$ ($1\le n\le 5\times 10^5$). The next line contains $n$ integers $a_1, \ldots, a_n$ ($1\le a_i\le n$ for all $1\le i\le n$) separated by single spaces. The next line contains a single integer $m$ ($1\le m\le 5\times 10^5$). Each of the next $m$ lines contains two integers $l$ and $r$ ($1\le l\le r\le n$) separated by a single space denoting a query.

Output Format

For each query, output one line containing the answer to that query.