[EC Final 2020] Prof. Pang's sequence

Luogu
IDLGP10822
Time3000ms
Memory256MB
DifficultyP6
2020O2优化ICPCEC Final
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 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 For each query, output one line containing the answer to that query. [samples]
Samples
Input #1
5
1 2 3 2 1
5
1 5
2 4
1 3
2 5
4 4
Output #1
10
3
4
6
1
Input #2
5
2 3 5 1 5
5
2 3
1 1
1 3
2 5
2 4
Output #2
2
1
4
6
4
Input #3
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 #3
4
2
4
4
16
16
12
6
9
6
API Response (JSON)
{
  "problem": {
    "name": "[EC Final 2020] Prof. Pang's sequence",
    "description": {
      "content": "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 numbe",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": {
      "LuoguStyle": "P6"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP10822"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Prof. Pang is given a fixed sequence $a_1, \\ldots, a_n$ and $m$ queries.\n\nEach query is specified by two integers $l$ and $r$ satisfying $1\\le l\\le r\\le n$. For each query, you should answer the numbe...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments