#P17140. [NOI 2026] 线段

    ID: 19488 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>动态规划 DPNOI交互题前缀和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 LL has nn segments contained in [1,m][1,m]。The ii-th (0i<n0\le i<n) segment is [li,ri][l_i,r_i] (1lirim1\le l_i\le r_i\le m)。

Xiao LL thinks that overly complicated segment intersection relationships are not elegant。For every segment set S{0,1,,n1}S\subseteq\{0,1,\ldots,n-1\}, Xiao LL defines SS to be elegant if and only if it satisfies the following:

  • Construct a graph whose vertex set corresponds to SS。There is an edge between vertex uu and vertex vv if and only if segment uu and segment vv intersect, i.e. there exists x[1,m]x\in[1,m] such that luxrul_u\le x\le r_u and lvxrvl_v\le x\le r_v。We say SS is elegant if and only if the constructed graph is exactly a tree.

Xiao LL wants to know how many segment sets are elegant, so he is given a positive integer kk (knk\le n)。You need to compute, for each s=1,2,,ks=1,2,\ldots,k, how many elegant sets of size ss there are.

Since the answer may be large, you only need to output the result modulo 998,244,353998,244,353

【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);
  • c,tc,t denote the test point ID and the number of testdata groups, respectively。c=0c=0 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);
  • n,m,kn,m,k denote the number of segments, the upper bound of the coordinate range, and the maximum set size to compute, respectively.
  • l,rl,r denote the left endpoints and right endpoints of each segment, respectively.
  • This function needs to return a sequence aa of length exactly k+1k+1, where a0=0a_0=0, and asa_s (1sk1\le s\le k) is the number of elegant sets of size ss modulo 998,244,353998,244,353.
  • For each test point, this function will be called by the judge exactly tt 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 KK be the sum of kk over all testdata within a single test point。For all testdata, we have:

  • 1t201\le t\le20
  • 1n30001\le n\le30001m1031\le m\le10^31kn1\le k\le nK200K\le200
  • For all 0i<n0\le i<n, we have 1lirim1\le l_i\le r_i\le m

::cute-table{tuack} | Test Point ID | nn\le | mm\le | KK\le | kk\le | Special Property | |:-:|:-:|:-:|:-:|:-:|:-:| | 131\sim3 | 2020 | 10210^2 | 2020 | 2020 | None | | 4,54,5 | 30003000 | 10310^3 | 200200 | 22 | ^ | | 686\sim8 | ^ | ^ | ^ | 33 | ^ | | 9,109,10 | 500500 | ^ | ^ | 200200 | AA | | 111511\sim15 | 30003000 | ^ | ^ | ^ | BB | | 161816\sim18 | 200200 | 500500 | 5050 | 5050 | CC | | 192119\sim21 | 500500 | 10310^3 | 200200 | 200200 | ^ | | 22,2322,23 | 10310^3 | 10210^2 | 3030 | 3030 | None | | 24,2524,25 | 30003000 | 10310^3 | 200200 | 200200 | ^ |

  • Special property AA: For all 0i,j<n0\le i,j<n with iji\ne j, segment ii does not contain segment jj, i.e. li>ljl_i>l_j or ri<rjr_i<r_j.
  • Special property BB: For all 0i<j<n0\le i<j<n, either segment ii contains segment jj, or segment ii and segment jj do not intersect, i.e. liljrjril_i\le l_j\le r_j\le r_i, ri<ljr_i<l_j, or li>rjl_i>r_j.
  • Special property CC: All 2n2n endpoints of the nn segments are pairwise distinct, i.e. l0,l1,,ln1,r0,r1,,rn1l_0,l_1,\ldots,l_{n-1},r_0,r_1,\ldots,r_{n-1} 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 c,tc,t.
    • Then follow the testdata groups. For each group of testdata:
      • The first line contains three positive integers n,m,kn,m,k.
      • Line i+2i+2 (0i<n0\le i<n) contains two positive integers li,ril_i,r_i.
  • The executable will output to standard output in the following format:
    • For each group of testdata, output one line with kk non-negative integers a1,a2,,aka_1,a_2,\ldots,a_k.
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 11 Explanation】

For the first group of testdata:

  • For size 11, the sets {0},{1},{2}\{0\},\{1\},\{2\} are all elegant.
  • For size 22, the sets {0,1},{1,2},{0,2}\{0,1\},\{1,2\},\{0,2\} are all elegant.
  • For size 33, the set {0,1,2}\{0,1,2\} constructs a 3-cycle, so it is not elegant.

Therefore the answers are 3,3,03,3,0.

For the second group of testdata:

  • For size 11, all 44 sets are elegant.
  • For size 22, {0,1},{1,2},{2,3}\{0,1\},\{1,2\},\{2,3\} are elegant.
  • For size 33, {0,1,2},{1,2,3}\{0,1,2\},\{1,2,3\} are elegant.
  • The size 44 set {0,1,2,3}\{0,1,2,3\} is elegant.

Therefore the answers are 4,3,2,14,3,2,1.

【Sample 22

See segment/segment2.in and segment/segment2.ans in the contestant directory.

This sample satisfies the constraints of test points 686\sim8.

【Sample 33

See segment/segment3.in and segment/segment3.ans in the contestant directory.

This sample satisfies the constraints of test points 9,109,10.

【Sample 44

See segment/segment4.in and segment/segment4.ans in the contestant directory.

This sample satisfies the constraints of test points 111511\sim15.

【Sample 55

See segment/segment5.in and segment/segment5.ans in the contestant directory.

This sample satisfies the constraints of test points 161816\sim18.

【Sample 66

See segment/segment6.in and segment/segment6.ans in the contestant directory.

This sample satisfies the constraints of test points 22,2322,23.

【Sample 77

See segment/segment7.in and segment/segment7.ans in the contestant directory.

This sample satisfies the constraints of test points 24,2524,25.

Translated by ChatGPT 5