Gift Boxes

시간 제한2초메모리 제한2048 MB

요약
팀 번호 수열에서 하나의 연속 구간을 지워 남은 수열에 같은 팀이 두 번 나오지 않도록 할 때, 지우는 구간의 길이를 최소로 하는 구간을 찾는다.
난이도

보통10점 중 7점

유형
투 포인터, 슬라이딩 윈도우, 배열, 해시맵
정답자
아직 제출이 없습니다

문제

This year's EGOI is organized in Bonn. The organizers want to distribute at most one gift box to every team in the contest, with each team represented by a number from 00 to T−1T-1. The contestants are standing in a single row. However they are mixed up such that people from the same team might not be standing next to each other. Note that there will be at least one team with more than one person in the row. There are NN people in the row. Person ii is part of the team a_ia\_i. The problem is: each team should only receive a maximum of one gift box. In order to ensure the process runs smoothly - and willing to leave some teams with no gift as a consequence - the organisers wish to pause the gifting process exactly once, skipping a few contestants before resuming the gift box handouts. In other words, they will skip one consecutive segment \[ℓ,r]\[\ell, r] of the contestants.

It is not necessary that every team receives a gift. Nevertheless, the organizers want to maximize the number of teams that will receive their gifts while ensuring that no team ends up with two or more gifts, equivalent to minimizing the number of contestants that are skipped under this condition. Please help the organizers to decide when it is best to pause and when to continue distributing gifts such that as few contestants as possible are skipped.

입력

The first line of input contains two integers, TT and NN -- the number of teams and the number of contestants in the row.

The second line contains NN integers, a_ia\_i, where the iith integer describes which team the person at position ii in the row belongs to. It is guaranteed that every integer between 00 and T−1T-1 appears at least once.

출력

Output two integers, ℓ\ell and rr, where ℓ\ell is the index of the first person that is skipped and rr is the index of the last skipped person. Note that ℓ\ell and rr are indexed from 00 to N−1N-1. If there is more than one solution, print any one of them.

제한

  • 1≤T<N≤500,0001 \leq T < N \leq 500\\,000.
  • 0≤a_i≤T−10 \leq a\_i \leq T-1.

예제6

  1. 예제 1

    입력
    4 5
    1 3 0 2 3
    
    예상 출력
    1 1
    
  2. 예제 2

    입력
    3 6
    1 0 2 2 1 0
    
    예상 출력
    0 2
    
  3. 예제 3

    입력
    4 8
    0 2 0 1 2 1 3 3
    
    예상 출력
    2 6
    
  4. 예제 4

    입력
    3 6
    1 1 2 0 1 0
    
    예상 출력
    0 3
    
  5. 예제 5

    입력
    4 6
    0 1 2 0 3 2
    
    예상 출력
    2 3
    
  6. 예제 6

    입력
    5 13
    3 3 3 1 2 0 3 3 2 1 4 1 0
    
    예상 출력
    1 9