#7. 「2020 AEC Final」G - Prof. Pang’s sequence

「2020 AEC Final」G - Prof. Pang’s sequence

题目描述

Prof. Pang is given a fixed sequence a1,,ana_1,…,a_n and mm queries.

Each query is specified by two integers ll and rr satisfying 1lrn1≤l≤r≤n. For each query, you should answer the number of pairs of integers (i,j)(i,j) such that lijrl≤i≤j≤r and the number of distinct integers in ai,,aja_i,…,a_j is odd.

输入格式

The first line contains a single integer n(1n5×105)n (1≤n≤5×10^5).

The next line contains nn integers a1,,ana_1,…,a_n (1ain1≤a_i≤n for all 1in1≤i≤n) separated by single spaces.

The next line contains a single integer m(1m5×105)m (1≤m≤5×10^5).

Each of the next m lines contains two integers ll and rr (1lrn)(1≤l≤r≤n) separated by a single space denoting a query.

输出格式

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

样例

input1
5
1 2 3 2 1
5
1 5
2 4
1 3
2 5
4 4
output1
10
3
4
6
1
input2
5
2 3 5 1 5
5
2 3
1 1
1 3
2 5
2 4
output2
2
1
4
6
4
input3
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
output3
4
2
4
4
16
16
12
6
9
6