Odd sum problem

5

2 votes
Algorithms, Hard, Square Root Decomposition
Problem

You are given an array A containing N integers. You have to answer Q queries.

Queries are of form:

L R

Here you have to fInd sum of all numbers Ai, for those Ai which has odd frequency in subarray L to R

INPUT CONSTRAINTS

  • 1N,Q105
  • 1Ai109
  • 1LRN

INPUT FORMAT

First line of input contains a single integer N, next line contains N space separated integers, elements of array A. Next line of input contains a single integer Q. Q lines follow each containing two space separated integer L and R.

OUTPUT Fvv

For each query, print the answer to the query in new line.

Hint:

Mo's Algorithm

Sample Input
5
1 2 2 2 1
3
1 3
1 4
1 5
Sample Output
1
7
6
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For query 1: 1 has frequency 1 and 2 has frequency 2 so, answer is 1

For query 2: 1 has frequency 1 and 2 has frequency 3 So, answer is 7

Contributers:
Editor Image

?