Sequence and Queries 4
Time limit4sMemory limit512 MB
For each query range [l,r], find the maximum distance between two positions in the range that hold the same value.
- Level
Medium7 of 10
- Topics
- Array, Prefix sum, Binary search, Sorting
- Solved
- No attempts yet
Problem
You are given a sequence of length whose elements are integers between 1 and . Write a program that answers the following query.
l r: print .
The pair also satisfies the condition, so the answer is always at least 0.
Input
The first line contains the length of the sequence () and ().
The second line contains . ()
The third line contains the number of queries ().
Each of the next lines contains one query, given as and . ()
Output
Print one answer per line for each query, in the order the queries are given.