#P5906. 【模板】回滚莫队&不删除莫队
【模板】回滚莫队&不删除莫队
Background
This is a template problem.
Problem Description
Given a sequence, you will be asked multiple queries on an interval . For each query, find the maximum distance between two equal numbers within the interval.
The distance between two elements in the sequence means the absolute difference of their indices.
Input Format
The first line contains an integer , which is the length of the sequence.
The second line contains integers describing the sequence.
The third line contains an integer , which is the number of queries.
Then follow lines, each containing two integers , representing the query interval.
Output Format
Output lines. Each line contains one integer, the answer. If there are no two equal numbers in the interval, output .
8
1 6 2 2 3 3 1 6
5
1 4
2 5
2 8
5 6
1 7
1
1
6
1
6
Hint
Let denote the elements of the sequence.
For of the testdata, , .
For of the testdata, , 。
Translated by ChatGPT 5