Random Permutation

시간 제한10초메모리 제한2048 MB

요약
무작위 순열이 주어질 때 현재 최솟값을 추가하고 양 끝 중 하나를 제거하는 과정으로 만들 수 있는 서로 다른 수열의 개수를 998244353으로 나눈 나머지로 구한다.
난이도

보통10점 중 6점

유형
조합론, 수학, 구현
정답자
아직 제출이 없습니다

문제

You are given a permutation pp consisting of nn integers from 11 to nn. You want to build a sequence aa from pp. To do that, you perform the following operation nn times:

  • append the minimum element of pp to the end of aa;
  • remove one of the ends of pp (either left or right).

You are given a random permutation pp. Your task is to calculate the number of different sequences aa that can be obtained in the way described above. This number can be very large, so find it modulo 998,244,353998\\,244\\,353. Two sequences are different if there is a position at which these sequences differ.

A permutation of size nn is a sequence of nn distinct integers from 11 to nn.

입력

The first line contains an integer tt (1≤t≤2⋅1051 \le t \le 2 \cdot 10^5), the number of test cases. The test cases follow.

The first line of each test case contains an integer nn, the size of the permutation (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5). The next line contains the permutation itself: nn distinct integers from 11 to nn. The permutation is generated using a pseudorandom number generator.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

출력

For each test case, output a line with a single integer: the required number modulo 998,244,353998\\,244\\,353.

예제1

  1. 예제 1

    입력
    4
    5
    4 3 5 1 2
    5
    5 3 1 2 4
    2
    2 1
    3
    1 3 2
    
    예상 출력
    8
    7
    2
    4