Odd sum problem
Practice
5 (2 votes)
Algorithms
Hard
Square root decomposition
Problem
34% Success 5861 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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 $$A_{i}$$, for those $$A_{i}$$ which has odd frequency in subarray L to R
INPUT CONSTRAINTS
- $$1 \le N,Q \le 10^5$$
- $$1 \le A_i \le 10^9$$
- $$1 \le L \le R \le N$$
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
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
4 votes
Tags:
AlgorithmsApprovedHard
Points:50
5 votes
Tags:
Square Root DecompositionAlgorithmsAdvanced Algorithms
Points:50
4 votes
Tags:
AlgorithmsHardSquare Root Decomposition
Editorial
Login to unlock the editorial