Number of Increasing Subsequences
InterviewTime limit2sMemory limit1024 MB
For each position i, count the increasing subsequences that end at A_i, modulo 998244353, where values range up to 5000.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Prefix sum, Array, Combinatorics
- Solved
- No attempts yet
Problem
You are given a sequence of length . For each , find the number of increasing subsequences that end with .
The answer can be very large, so output it modulo .
For those who are not sure what an increasing subsequence is, Dongwon has prepared the following definitions.
- A subsequence is a sequence obtained by choosing one or more elements from the given sequence and listing them in their original order.
- An increasing subsequence is a sequence in which every element except the first is greater than the element immediately before it. That is, for a subsequence of length , if holds for all , then is an increasing subsequence.
Dongwon adds a note that, by this definition, a subsequence of length 1 is always an increasing subsequence.
Input
The first line gives the length of the sequence, .
The second line gives integers separated by spaces.
Output
Print integers on the first line.
The -th number printed is the number of increasing subsequences ending with , modulo .