#P17140. [NOI 2026] 线段
[NOI 2026] 线段
Background
The statement and sample attachments are from QOJ。
When submitting to Luogu, you do not need to include the header #include "segment.h"。Just copy
void init(int c, int t);
std::vector<int> segment(int n, int m, int k, std::vector<int> l, std::vector<int> r);
to the beginning of your program, and compile with a C++17 or higher compiler.
Problem Description
Xiao has segments contained in 。The -th () segment is ()。
Xiao thinks that overly complicated segment intersection relationships are not elegant。For every segment set , Xiao defines to be elegant if and only if it satisfies the following:
- Construct a graph whose vertex set corresponds to 。There is an edge between vertex and vertex if and only if segment and segment intersect, i.e. there exists such that and 。We say is elegant if and only if the constructed graph is exactly a tree.
Xiao wants to know how many segment sets are elegant, so he is given a positive integer ()。You need to compute, for each , how many elegant sets of size there are.
Since the answer may be large, you only need to output the result modulo 。
【How to use the test program】
Contestants do not need to, and should not, implement the main function。
Contestants must ensure that the submitted source file includes the header segment.h, i.e. add the following code at the beginning of the program:
#include "segment.h"
Contestants need to implement the following two functions in the submitted source file segment.cpp:
void init(int c, int t);
- denote the test point ID and the number of testdata groups, respectively。 means this test point is the sample.
- For each test point, this function will be called by the judge exactly once when the program starts.
std::vector<int> segment(int n, int m, int k, std::vector<int> l, std::vector<int> r);
- denote the number of segments, the upper bound of the coordinate range, and the maximum set size to compute, respectively.
- denote the left endpoints and right endpoints of each segment, respectively.
- This function needs to return a sequence of length exactly , where , and () is the number of elegant sets of size modulo .
- For each test point, this function will be called by the judge exactly times.
template_segment.cpp in this problem directory is the provided sample code. Contestants may refer to it and implement their own code.
Constraints
Let be the sum of over all testdata within a single test point。For all testdata, we have:
- ;
- ,,,;
- For all , we have 。
::cute-table{tuack} | Test Point ID | | | | | Special Property | |:-:|:-:|:-:|:-:|:-:|:-:| | | | | | | None | | | | | | | ^ | | | ^ | ^ | ^ | | ^ | | | | ^ | ^ | | | | | | ^ | ^ | ^ | | | | | | | | | | | | | | | ^ | | | | | | | None | | | | | | | ^ |
- Special property : For all with , segment does not contain segment , i.e. or .
- Special property : For all , either segment contains segment , or segment and segment do not intersect, i.e. , , or .
- Special property : All endpoints of the segments are pairwise distinct, i.e. are all different.
Input Format
You can compile in this problem directory using the following command to obtain an executable file:
g++ grader.cpp segment.cpp -o segment -O2 -std=c++14 -static
For the compiled executable segment:
- The executable will read input from standard input in the following format:
- The first line contains two non-negative integers .
- Then follow the testdata groups. For each group of testdata:
- The first line contains three positive integers .
- Line () contains two positive integers .
- The executable will output to standard output in the following format:
- For each group of testdata, output one line with non-negative integers .
0 3
3 3 3
1 2
2 3
1 3
4 5 4
1 2
2 3
3 4
4 5
4 2 3
1 2
1 2
1 2
1 1
3 3 0
4 3 2 1
4 6 0
Hint
【Sample Explanation】
For the first group of testdata:
- For size , the sets are all elegant.
- For size , the sets are all elegant.
- For size , the set constructs a 3-cycle, so it is not elegant.
Therefore the answers are .
For the second group of testdata:
- For size , all sets are elegant.
- For size , are elegant.
- For size , are elegant.
- The size set is elegant.
Therefore the answers are .
【Sample 】
See segment/segment2.in and segment/segment2.ans in the contestant directory.
This sample satisfies the constraints of test points .
【Sample 】
See segment/segment3.in and segment/segment3.ans in the contestant directory.
This sample satisfies the constraints of test points .
【Sample 】
See segment/segment4.in and segment/segment4.ans in the contestant directory.
This sample satisfies the constraints of test points .
【Sample 】
See segment/segment5.in and segment/segment5.ans in the contestant directory.
This sample satisfies the constraints of test points .
【Sample 】
See segment/segment6.in and segment/segment6.ans in the contestant directory.
This sample satisfies the constraints of test points .
【Sample 】
See segment/segment7.in and segment/segment7.ans in the contestant directory.
This sample satisfies the constraints of test points .
Translated by ChatGPT 5