トヨタシステムズプログラミングコンテスト2023(AtCoder Beginner Contest 330)
G
Inversion Squared
AtCoder
⌀ 3455
原题
翻译中…

Problem Statement

翻译中…

You are given a sequence $A = (A_1,\ldots,A_N)$ of length $N$. Each element of $A$ is either $-1$ or an integer between $1$ and $N$, and each integer from $1$ to $N$ is contained at most once.

翻译中…

A permutation $P=(P_1,\ldots,P_N)$ of $(1,\ldots,N)$ is called a good permutation if and only if it satisfies $A_i \neq -1 \Rightarrow P_i = A_i$. Find the sum of the squares of the inversion numbers of all good permutations, modulo $998244353$.

翻译中…

The inversion number of a permutation $P$ is the number of pairs of integers $(i,j)$ such that $1\leq i < j \leq N$ and $P_i > P_j$.

翻译中…

Constraints

翻译中…
  • $1\leq N\leq 3000$
  • $A_i = -1$ or $1\leq A_i \leq N$.
  • Each integer from $1$ to $N$ is contained at most once in $A$.
  • All input values are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 \ldots A_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
4
3 -1 2 -1
Output #1
29
There are two good permutations: $P=(3,1,2,4)$ and $P=(3,4,2,1)$, with inversion numbers $2$ and $5$, respectively. Thus, the answer is $2^2 + 5^2 = 29$.
Input #2
10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
Output #2
952235647
Input #3
15
-1 -1 10 -1 -1 -1 2 -1 -1 3 -1 -1 -1 -1 1
Output #3
460544744
Find the sum modulo $998244353$.
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。