#P8958. 「CGOI-3」残暴圣所

    ID: 9812 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>洛谷原创O2优化快速傅里叶变换 FFT快速数论变换 NTT

「CGOI-3」残暴圣所

Background

After finally clearing the Spring 2 Heart Gate, ac arrived at Spring 3 and decided to predict the difficulty of Ferocious Sanctuary.

Problem Description

To clear Ferocious Sanctuary, ac needs to perform nn operations during the next 2n2n moments. The ii-th operation requires pressing a key at time lil_i, then holding this key until releasing it at time rir_i (li<ril_i<r_i). At each moment, ac either presses a key or releases a key, but can hold multiple keys at the same time.

The ii-th operation forms an operation interval [li,ri][l_i,r_i], and lil_i is strictly increasing. Also, due to the level design of Ferocious Sanctuary, for any two operations, their operation intervals either do not intersect, or one contains the other.

ac designed 2n2n difficulty coefficients a1,a2,,a2na_1,a_2,\dots,a_{2n}. The difficulty of the ii-th operation can be evaluated as ali×aria_{l_i}\times a_{r_i}, and the difficulty of clearing Ferocious Sanctuary is the sum of the difficulties of all operations.

However, since ac is stuck on the first screen of Ferocious Sanctuary, he does not know the operation intervals of each operation. Given nn and {a}\{a\}, please compute, over all possible cases, the sum of the clearing difficulty, modulo 998244353998244353.

Formal statement:

Given a sequence a1,a2,,a2na_1,a_2,\dots,a_{2n} of length 2n2n.

Define an "interval group" as a set of nn intervals, where the ii-th interval is [li,ri] (1li<ri2n)[l_i,r_i]\ (1\le l_i<r_i\le2n). For all interval groups satisfying the conditions below, compute the sum of i=1nali×ari\sum_{i=1}^na_{l_i}\times a_{r_i}, modulo 998244353998244353:

  1. l1,r1,l2,r2,,ln,rnl_1,r_1,l_2,r_2,\dots,l_n,r_n is a permutation of 1,2,,2n1,2,\dots,2n.
  2. 1i<n\forall 1\le i<nli<li+1l_i<l_{i+1}
  3. i,j\forall i,j[li,ri][lj,rj]=[l_i,r_i]\cap[l_j,r_j]=\varnothing or [li,ri][lj,rj][l_i,r_i]\sube[l_j,r_j] or [lj,rj][li,ri][l_j,r_j]\sube[l_i,r_i]

Input Format

The first line contains an integer nn, representing the number of intervals.

The second line contains 2n2n integers aia_i, with the meaning described above.

Output Format

Output one integer in one line, representing the answer modulo 998244353998244353.

2
114 514 1919 810
2691692
3
1 1 4 5 1 4
98
8
275272885 418731188 289662326 114331587 192436268 885936831 877490593 508774565 633402863 149033362 995239139 494498006 168828873 138947653 983144753 844326228
349824160

Hint

Sample Explanation

For sample 1, there are only two possible interval groups:

  1. [1,2],[3,4][1,2],[3,4], the clearing difficulty is a1a2+a3a4=1612986a_1a_2+a_3a_4=1612986
  2. [1,4],[2,3][1,4],[2,3], the clearing difficulty is a1a4+a2a3=1078706a_1a_4+a_2a_3=1078706

The sum of difficulties is 1612986+1078706=26916921612986+1078706=2691692, and modulo 998244353998244353 it is still 26916922691692.

The following cases are invalid:

  1. [3,4],[1,2][3,4],[1,2], because lil_i is required to be strictly increasing, but l1l2l_1\ge l_2
  2. [1,1],[2,4][1,1],[2,4], because li<ril_i<r_i is required, but l1r1l_1\ge r_1
  3. [1,3],[2,3][1,3],[2,3], because at each moment, one must either press a key or release a key, but at the third moment two keys are released, and at the fourth moment no key is pressed or released.
  4. [1,3],[2,4][1,3],[2,4], because any two operation intervals must be disjoint or one contains the other, but these two intervals intersect and neither contains the other.

Constraints

For 10%10\% of the testdata, n15n\le15

For 30%30\% of the testdata, n200n\le200

For 50%50\% of the testdata, n3000n\le3000

For another 5%5\% of the testdata, ai=1a_i=1

For 100%100\% of the testdata, 1n5×1051\le n\le5\times10^50ai<9982443530\le a_i<998244353

Translated by ChatGPT 5