#P9330. [JOISC 2023 Day1] Festivals in JOI Kingdom 2
[JOISC 2023 Day1] Festivals in JOI Kingdom 2
题目描述
In JOI Kingdom, a national festival is held once a year. During the period of the festival, there are events in total. The schedule for each event is already fixed. The schedule of the events are described by sequences of length satisfying the following conditions.
- Every integer between and , inclusive, appears as an element of or .
- .
- .
The -th event will start at minutes after the beginning of the festival, and end at minutes after the beginning of the festival.
Participants of the festival may choose any events in which they will participate. However, it is not allowed to participate in two events whose schedules overlap. (Note that the starting times and the ending times of the events are different from each other.)
JOI-kun wants to participate in as many events as possible. Until last year, he chose the events in which he participated by the following procedures on a computer.
For ,the following are done in this order.
If the schedule of the -th event does not overlap the schedules of the other events in which he already chose to participate, he will participate in the -th event. Otherwise, he will not participate in the -th event.
However, after studying computer science, JOI-kun noticed that the above algorithm does not necessarily maximize the number of events in which JOI-kun will participate. From this year, JOI-kun will use an improved algorithm. Using the improved algorithm, JOI-kun will be able to maximize the number of events in which JOI-kun will participate.
JOI-kun wants to know the number of cases where the improved algorithm produces a larger number of events.
Write a program which, given the integer and a large prime number , calculates the number of pairs of sequences describing the schedules of the events for which the improved algorithm produces a larger number of events. Since the answer can be very large, your program should output the remainder of the answer when divided by .
输入格式
Read the following data from the standard input.
输出格式
Write one line to the standard output. The output should contain the remainder of the answer, the number of pairs of sequences describing the schedules of the events for which the improved algorithm produces a larger number of events, when divided by .
题目大意
对于以下问题:
给定长度为 的序列 、,满足以下条件:
- 在序列 与序列 中, 到 的整数各出现恰好一次;
- 对于 ,;
- 对于 ,。
求:最多能在 中选出多少个两两不交的区间。
考虑以下算法:
从 到 枚举 ,若 与所有已经选择的区间都不交,则选择该区间。最后输出选择的区间数。
给定 ,求:有多少个满足条件的序列对 ,使得以上算法无法求出正确的结果。答案对 取模。
3 100000007
2
4 100000007
28
15 999999937
935834920
提示
【样例解释 #1】
For example, consider the case where and . If JOI-kun uses the algorithm used until last year, he will participate in the first event only. On the other hand, if he uses a correct algorithm to maximize the number of events, he will participate in the second event and the third event. Thus, he will participate in two events. In this case, the improved algorithm produces a larger number of events.
The following are the pair of sequences for which the improved algorithm produces a larger number of events.
Therefore, output , which is the remainder of when divided by .
该样例满足所有子任务的限制。
【样例解释 #2】
There are pairs of sequences satisfying the condition. Therefore, output , which is the remainder of when divided by .
该样例满足所有子任务的限制。
【样例解释 #3】
There are pairs of sequences satisfying the condition. Therefore, output , which is the remainder of when divided by .
该样例满足子任务 的限制。
【数据范围】
对于所有测试数据,满足 ,,保证 是质数,保证所有输入均为整数。
子任务编号 | 分值 | |
---|---|---|