E - Odd Inversion 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 800 点

問題文

長さが N の正整数列 A = (A_1, A_2, \cdots, A_N) が与えられます.ここで,A_1 \leq A_2 \leq \cdots \leq A_N が成立します.

以下の条件を満たす長さが N の正整数列 B としてありうる個数を 998\,244\,353 で割ったあまりを求めてください.

  • 1 \leq B_i \leq A_i (1 \leq i \leq N)
  • B の転倒数は奇数

ここで,B の転倒数とは 1 \leq i < j \leq N を満たす整数の組 (i, j) で B_i > B_j であるものの個数を表します.

1 つの入力ファイルにつき,T 個のテストケースを解いてください.

制約

  • 1 \leq T \leq 10\,000
  • 1 \leq N \leq 200\,000
  • 1 \leq A_1 \leq A_2 \leq \cdots \leq A_N \leq 10^9
  • T 個のテストケースにおける N の総和は 400\,000 以下
  • 入力される値はすべて整数である

入力

入力は以下の形式で標準入力から与えられる.ここで,\mathrm{case}_i (1 \leq i \leq T) は i 番目のテストケースを意味する.

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

各テストケースは以下の形式で与えられる.

N
A_1 A_2 \cdots A_N

出力

T 行出力せよ.i 行目 (1 \leq i \leq T) には \mathrm{case}_i に対する答えを出力せよ.


入力例 1

3
2
2 3
3
2 2 3
5
699498 707559 724350 759726 769395

出力例 1

1
3
610589585
  • 1 番目のテストケースについて,(2, 1) が条件を満たします.
  • 2 番目のテストケースについて,(1, 2, 1), (2, 1, 2), (2, 1, 3) が条件を満たします.

Score : 800 points

Problem Statement

You are given a sequence of positive integers A = (A_1, A_2, \cdots, A_N) of length N. Here, A_1 \leq A_2 \leq \cdots \leq A_N holds.

Find the number, modulo 998\,244\,353, of possible sequences of positive integers B of length N satisfying the following conditions.

  • 1 \leq B_i \leq A_i (1 \leq i \leq N)
  • The inversion number of B is odd.

Here, the inversion number of B is the number of pairs of integers (i, j) satisfying 1 \leq i < j \leq N such that B_i > B_j.

Solve T test cases per input file.

Constraints

  • 1 \leq T \leq 10\,000
  • 1 \leq N \leq 200\,000
  • 1 \leq A_1 \leq A_2 \leq \cdots \leq A_N \leq 10^9
  • The sum of N over the T test cases is at most 400\,000.
  • All input values are integers.

Input

The input is given from Standard Input in the following format. Here, \mathrm{case}_i (1 \leq i \leq T) denotes the i-th test case.

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

Each test case is given in the following format:

N
A_1 A_2 \cdots A_N

Output

Output T lines. The i-th line (1 \leq i \leq T) should contain the answer for \mathrm{case}_i.


Sample Input 1

3
2
2 3
3
2 2 3
5
699498 707559 724350 759726 769395

Sample Output 1

1
3
610589585
  • For the first test case, (2, 1) satisfies the conditions.
  • For the second test case, (1, 2, 1), (2, 1, 2), (2, 1, 3) satisfy the conditions.