#P7907. [Ynoi2005] rmscne

[Ynoi2005] rmscne

Problem Description

Given a sequence of length nn and qq queries, for each query interval [l,r][l,r], find the shortest sub-interval [l,r][l',r'] such that every number that appears in [l,r][l,r] also appears in [l,r][l',r']. You only need to output the length of [l,r][l',r'], i.e. rl+1r'-l'+1.

Input Format

The first line contains one positive integer nn.

The next line contains nn positive integers, representing the elements of the sequence.

The next line contains one positive integer qq.

The next qq lines each contain two positive integers l,rl,r, representing a query.

Output Format

Output qq lines, each containing one positive integer representing the answer.

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

Hint

Idea: qwaszx, Solution: qwaszx, Code: qwaszx, Data: qwaszx.

For 20%20\% of the testdata, n,q,ai5×103n,q,a_i\leq 5\times 10^3.

For 50%50\% of the testdata, n,q,ai5×104n,q,a_i\leq 5\times 10^4.

For 100%100\% of the testdata, 1n,q2×1061\leq n,q\leq 2\times 10^6, 1ain1\leq a_i\leq n.

Translated by ChatGPT 5