A counting problem

4

1 votes
Datastructures, Dynamic Programming, Algorithms, Medium
Problem

You have been given an integer N and N segments [Li,Ri]1iN. Now, we call a set of distinct integers {k1,k2,...,kx},1kiN good, if it is possible to arrange the integers in the set in some particular order to form a sequence c1,c2...cx, such that :

The Segment with index ci contains segment with index ci1,2ix. Segments are indexed by the order in which they appear in the input, beggining with 1.

A segment [Lx,Rx] is said to contain a segment [Ly,Ry], if LxLy and RxRy. Now, for each j from 1 to N, you need find the number of good subsets of size j.

Print these numbers in increasing order of j. As these numbers can be rather large, print them Modulo 998244353, a widely used prime.

Input Format :

The first line contains a single integer N. Each of the next N lines contain 2 space separated integers, where the 2 integers on the ith line denote Li,Ri.

Output Format

Print N space separated integers. Note that all the integers need to be printed Modulo 998244353

Constraints :

1N3000

1LiRi2109

Time Limit: 1.5
Memory Limit: 512
Source Limit:
Explanation

The good subsets of size 1 are {1},{2},{3}, and the good subsets of size 2 are {1,2},{2,3}

The subset {1,2} is good since we can form the sequence 2,1, since segment with index 1 from the input contains the segment with index 2.

Similarily, the subset {2,3} is good since we can arrange the integers to form the sequence 2,3 since we know the segment with index 3 from the input contains the segment with index 2

Editor Image

?