Random Permutation
시간 제한10초메모리 제한2048 MB
무작위 순열이 주어질 때 현재 최솟값을 추가하고 양 끝 중 하나를 제거하는 과정으로 만들 수 있는 서로 다른 수열의 개수를 998244353으로 나눈 나머지로 구한다.
문제
You are given a permutation consisting of integers from to . You want to build a sequence from . To do that, you perform the following operation times:
- append the minimum element of to the end of ;
- remove one of the ends of (either left or right).
You are given a random permutation . Your task is to calculate the number of different sequences that can be obtained in the way described above. This number can be very large, so find it modulo . Two sequences are different if there is a position at which these sequences differ.
A permutation of size is a sequence of distinct integers from to .
입력
The first line contains an integer (), the number of test cases. The test cases follow.
The first line of each test case contains an integer , the size of the permutation (). The next line contains the permutation itself: distinct integers from to . The permutation is generated using a pseudorandom number generator.
The sum of over all test cases does not exceed .
출력
For each test case, output a line with a single integer: the required number modulo .