Record Parity
Time limit1sMemory limit1024 MB
Given a permutation, find the sum of (-1)^len over all subsequences with exactly k records (left-to-right maxima), modulo 998244353.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
You are given a permutation of length and an integer .
An element is called a record if it is strictly greater than all the elements before it.
Calculate the sum of over all subsequences that have exactly records. Here is the number of elements in the subsequence. Since the answer can be large, calculate it modulo .
Input
The first line contains two integers and ().
The second line contains the permutation .
Output
I'll let you guess this one.
Hint
In the second sample, all subsequences of length 3 have exactly 3 records, and no other subsequence has exactly 3 records. The sum is therefore , which is modulo .
In the third sample, none of the subsequences have exactly 5 records, and the sum over the empty set is 0.