#P8317. [FOI2021] 幸运区间
[FOI2021] 幸运区间
Background
Fujian Province Youth Informatics Programming Level Certification 2021, Problem 4.
Problem Description
A lottery event is taking place. Each participant receives sequences. Each sequence contains positive integers, and there is also a number , meaning that among these positive integers, there exist lucky numbers.
Each participant chooses several consecutive sequences from their own sequences to form an interval, called a candidate interval. If every sequence in the candidate interval contains at least one lucky number, then this interval is called a lucky interval. Of course, there may be more than one lucky interval. The rules say that the lucky interval containing the most sequences (i.e., with the greatest total length) is called the super lucky interval.
For example, when , the sequences are:
- Sequence :
115 120. - Sequence :
50 80. - Sequence :
199 30. - Sequence :
40 40. - Sequence :
30 30. - Sequence :
25 40.
The interval from sequence to sequence is a lucky interval, because each sequence from to contains , , or , for a total of lucky numbers. The interval from sequence to sequence is also a lucky interval, because all sequences from to contain , , or , and it contains sequences, so it is the super lucky interval with the greatest total length.
Each participant wants to know what their super lucky interval is. The programming task is: for each participant, output the index of the first element and the index of the last element of the super lucky interval with the greatest total length. If there are multiple intervals with the same maximum length, output the one with the smallest first index. Note that indices start from .
Input Format
The first line contains an integer , representing the number of participants who received sequences.
Then follow groups of data, each describing one participant’s sequence information.
The first line of each group contains three positive integers , as described above. The next line contains integers: the first integers represent sequence , the next represent sequence , and so on.
Output Format
For each participant, output one line: Case #x: y z, where is the number (starting from ), and and are the indices of the first and last elements of the answer interval.
(There is one space between Case and #; there is no space between # and x; there is one space after : before y; there is one space between y and z.)
4
8 1 2
1 2 3 2 4 5 4 6
4 3 2
1 2 3 4 5 6 7 8 9 10 11 12
6 2 3
10 20 50 60 70 30 40 40 30 30 20 40
10 1 3
2 4 3 1 4 5 3 1 1 2
Case #1: 1 3
Case #2: 0 1
Case #3: 1 5
Case #4: 1 4
Hint
Constraints
For of the testdata, .
For of the testdata, .
The first two parts together account for .
For of the testdata, .
The input file is within , each number in each sequence .
For at most , ; for all other , .
Translated by ChatGPT 5