Hard Problem
Time limit1sMemory limit1024 MB
Sum (last element + 10) times f_m over even-length subsegments whose two halves have maxima differing by at most k, modulo 998244353.
- Level
Hard8 of 10
- Topics
- Divide and conquer, Stack, Segment tree
- Solved
- No attempts yet
Statement
You are given an integer array . A subsegment of even length is called good if .
Define an integer sequence as follows:
- for
Calculate the sum of over all good subsegments. Since this number can be large, print it modulo 998244353.
Input
The first line contains a single integer (), the number of test cases. Each test case starts with a line containing two integers and (, ).
The next line contains integers ().
The sum of over all test cases does not exceed .
Output
For each test case, print a single integer, the answer to the problem.