#P9991. [Ynoi Easy Round 2023] TEST_107

[Ynoi Easy Round 2023] TEST_107

Problem Description

Given a sequence aa of length nn with indices from 11 to nn, there are mm queries. Each query gives an interval [l,r][l,r]. You need to find a sub-interval [l,r][l',r'] satisfying llrrl\le l'\le r'\le r, such that the number of distinct values that appear in [l,r][l',r'] is less than the number of distinct values that appear in [l,r][l,r], and its length rl+1r'-l'+1 is as large as possible. If no such sub-interval exists, output 00.

Input Format

The first line contains two integers n,mn,m.

The next line contains nn integers, which are the elements of the sequence aa.

Then follow mm lines, each containing two integers l,rl,r representing a query. You only need to output the length of the sub-interval, i.e. rl+1r'-l'+1.

Output Format

For each query, output one integer per line representing the answer.

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

Hint

Idea: ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078.

Constraints:

For 20%20\% of the testdata, n,m100n,m\le100.

For 40%40\% of the testdata, n,m1000n,m\le1000.

For another 20%20\% of the testdata, ai10a_i\le 10.

For 100%100\% of the testdata, 1n,m,ai2×1061\le n,m,a_i\le 2\times 10^6.

Translated by ChatGPT 5