DMOPC '16 Contest 4 P4 - Molly and Manga Shopping

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type

After getting over the initial shock of the variety of candy apples, Molly finally decides to explore the carnival.

However, she had not taken two steps when the sign of a giant manga booth caught her eye. There are N different volumes of manga lined up in a row, the ith of which belongs to the aith series.

Molly is eager to explore the rest of the carnival but cannot resist perusing this grand selection of manga. However, Molly is a cat and therefore cannot read. Additionally, she can only focus on one contiguous interval of the manga display at a time.

You recall that Molly considers a series of manga in an interval interesting if their frequency in that interval is even (and positive).

Can you write a program to help Molly determine the amount of interesting manga?

Input Specification

Line 1: One integer N, denoting the number of volumes of manga on display.
Line 2: N space-separated integers ai (1iN), denoting the series number of the ith volume.
Line 3: One integer Q, denoting the number of queries Molly will give.
Next Q lines: Two space-separated integers pj,qj (1jQ) denoting the left- and rightmost manga included in Molly's queried interval.

Output Specification

Your program should output Q integers, each on their own line, denoting the number of manga series with an even frequency in the queried interval in the order they are given in the input.

Constraints

For all subtasks:

1pjqjN

1ai105

Subtask Points N Q
1 30 1N100 1Q100
2 70 1N105 1Q105

Sample Input

Copy
5
1 2 3 2 1
3
3 3
2 4
1 5

Sample Output

Copy
0
1
2

Comments

There are no comments at the moment.