#P16582. [GKS 2016 #B] Watson and Intervals
[GKS 2016 #B] Watson and Intervals
题目描述
Sherlock and Watson have mastered the intricacies of the language in their programming course, so they have moved on to algorithmic problems. In today's class, the tutor introduced the problem of merging one-dimensional intervals. intervals are given, and the th interval is defined by the inclusive endpoints , where .
The tutor defined the covered area of a set of intervals as the number of integers appearing in at least one of the intervals. (Formally, an integer contributes to the covered area if there is some such that .)
Now, Watson always likes to challenge Sherlock. He has asked Sherlock to remove exactly one interval such that the covered area of the remaining intervals is minimized. Help Sherlock find this minimum possible covered area, after removing exactly one of the intervals.
输入格式
Each test case consists of one line with eight integers , , , , , , , and . is the number of intervals, and the other seven values are parameters that you should use to generate the other intervals, as follows:
First define and . Then, use the recurrences below to generate , for to :
- $x_i = (A\times x_{i-1} + B\times y_{i-1} + C_1) \text{ modulo } M$.
- $y_i = (A\times y_{i-1} + B\times x_{i-1} + C_2) \text{ modulo } M$.
We define and , for all to .
输出格式
For each test case, output one line containing Case #: , where is the test case number (starting from ) and is the minimum possible covered area of all of the intervals remaining after removing exactly one interval.
3
1 1 1 1 1 1 1 1
3 2 5 1 2 3 4 10
4 3 4 3 3 8 10 10
Case #1: 0
Case #2: 4
Case #3: 9
提示
In case , using the generation method, the set of intervals generated are: . Removing the only interval, the covered area is .
In case , using the generation method, the set of intervals generated are: . Removing the first, second or third interval would cause the covered area of remaining intervals to be , and , respectively.
In case , using the generation method, the set of intervals generated are: . Removing the first, second, third or fourth interval would cause the covered area of remaining intervals to be , , and , respectively.
Limits
.
.
.
.
.
.
.
Small dataset (Test set 1 - Visible)
.
Large dataset (Test set 2 - Hidden)
.