#P13339. [EGOI 2025] Gift Boxes

    ID: 15205 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>贪心2025Special Judge双指针 two-pointerEGOI(欧洲/女生)

[EGOI 2025] Gift Boxes

题目描述

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 T1T-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 aia_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 organizers 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, aia_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 T1T-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 N1N-1. If there is more than one solution, print any one of them.

4 5
1 3 0 2 3
1 1
3 6
1 0 2 2 1 0
0 2
4 8
0 2 0 1 2 1 3 3
2 6
3 6
1 1 2 0 1 0
0 3
4 6
0 1 2 0 3 2
2 3
5 13
3 3 3 1 2 0 3 3 2 1 4 1 0
1 9

提示

Examples

The first sample satisfies the constraints of test groups 1, 3, 5 and 6. Two different outputs are possible: 1 11 \ 1 corresponding to the solid blue line and 4 44 \ 4 corresponding to the red dotted line, as described in the picture below. Either way, all four teams receive gifts and no team receives more than one gift.

$\begin{array}{lllll} 1 & \blue 3 & 0 & 2 & \red 3 \end{array}$

The second sample satisfies the constraints of test groups 2, 3, 4, 5 and 6. Again, two different outputs are possible: 0 20 \ 2 and 3 53 \ 5, as described in the picture below. In both cases, all three teams receive gifts.

$\begin{array}{lllll} \blue 1 & \blue 0 & \blue 2 & \red 2 & \red 1 & \red 0 \end{array}$

The third sample satisfies the constraints of test groups 3, 4, 5, 6. The optimal solution is that three teams receive a gift, as shown below. The contestants with indices 0, 1 and 7, who are in teams 0, 2 and 3, respectively, receive gifts. This is the only possible solution.

$\begin{array}{lllllll} 0 & 2 & \blue 0 & \blue 1 & \blue 2 & \blue 1 & \blue 3 & 3 \end{array}$

The fourth sample satisfies the constraints of test groups 3, 5 and 6. Again two different outputs are possible: 0 30 \ 3 and 1 41 \ 4, as described in the picture below. In both cases, exactly two teams (team 0 and team 1) receive gifts. Team 2 does not receive a gift as doing so would require giving team 0 or 1 two gifts, which is strictly forbidden.

$\begin{array}{lllllll} \blue 1 & \blue 1 & \blue 2 & \blue 0 & 1 & 0 \end{array}$

$\begin{array}{lllllll} 1 & \red 1 & \red 2 & \red 0 & \red 1 & 0 \end{array}$

The fifth sample satisfies the constraints of test groups 3, 5 and 6. The only possible answer is 2 32 \ 3, as described in the picture below. All four teams receive gifts.

$\begin{array}{lllllll} 0 & 1 & \blue 2 & \blue 0 & 3 & 2 \end{array}$

The sixth sample satisfies the constraints of test groups 3, 5 and 6. A maximum of four out of five teams can receive a gift, as shown below. The contestants with indices 0, 10, 11 and 12, who are in teams 3, 4, 1 and 0, respectively, receive gifts. This is the only possible solution.

$\begin{array}{lllllll} 3 & \blue 3 & \blue 3 & \blue 1 & \blue 2 & \blue 0 & \blue 3 & \blue 3 & \blue 2 & \blue 1 & 4 & 1 & 0 \end{array}$

Constraints and Scoring

  • 1T<N5000001 \leq T < N \leq 500\,000.
  • 0aiT10 \leq a_i \leq T-1.

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group, you need to solve all test cases in the test group.

Group Score Limits
1 8 N=T+1N = T + 1, i.e. only one team will appear twice
2 11 N=2TN = 2 \cdot T and every team will appear exactly once in the first half and exactly once in the second half of the line
3 14 1T<N5001 \leq T < N \leq 500
4 21 N=2TN = 2 \cdot T and every team will appear twice
5 22 1T<N50001 \leq T < N \leq 5\,000
6 24 No additional constraints