luogu#P1638. 逛画展

    ID: 629 Type: RemoteJudge 1000ms 128MiB Tried: 1 Accepted: 1 Difficulty: 5 Uploaded By: Tags>二分USACO单调队列队列双指针 two-pointer

逛画展

Problem Description

The exhibition hall is displaying paintings by the world’s best mm painters.

When buying a ticket, a visitor must specify two numbers, xx and yy, meaning they want to see all paintings from the xx-th to the yy-th (inclusive), and the ticket price is one yuan per painting.

Sept hopes that, after entering, he can see paintings by all the master painters. Of course, he wants to minimize the ticket price.

Find the x,yx, y he should choose when buying the ticket. The testdata guarantees that a solution exists.

If multiple solutions exist, output the one with the smallest xx.

Input Format

The first line contains two integers n,mn, m, denoting the total number of paintings in the exhibition and the number of master painters, respectively.

The second line contains nn integers aia_i, where aia_i is the ID of the master who painted the ii-th painting.

Output Format

One line with two integers x,yx, y.

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

2 7

Hint

Constraints

  • For 30% of the testdata, n200n \le 200, m20m \le 20.
  • For 60% of the testdata, n105n \le 10^5, m103m \le 10^3.
  • For 100% of the testdata, 1n1061 \le n \le 10^6, 1aim2×1031 \le a_i \le m \le 2 \times 10^3.

Translated by ChatGPT 5