CF1096F.Inversion Expectation
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A permutation of size n is an array of size n such that each integer from 1 to n occurs exactly once in this array. An inversion in a permutation p is a pair of indices (i,j) such that i>j and ai<aj . For example, a permutation [4,1,3,2] contains 4 inversions: (2,1) , (3,1) , (4,1) , (4,3) .
You are given a permutation p of size n . However, the numbers on some positions are replaced by −1 . Let the valid permutation be such a replacement of −1 in this sequence back to numbers from 1 to n in such a way that the resulting sequence is a permutation of size n .
The given sequence was turned into a valid permutation randomly with the equal probability of getting each valid permutation.
Calculate the expected total number of inversions in the resulting valid permutation.
It can be shown that it is in the form of QP where P and Q are non-negative integers and Q=0 . Report the value of P⋅Q−1(mod998244353) .
输入格式
The first line contains a single integer n ( 1≤n≤2⋅105 ) — the length of the sequence.
The second line contains n integers p1,p2,…,pn ( −1≤pi≤n , pi=0 ) — the initial sequence.
It is guaranteed that all elements not equal to −1 are pairwise distinct.
输出格式
Print a single integer — the expected total number of inversions in the resulting valid permutation.
It can be shown that it is in the form of QP where P and Q are non-negative integers and Q=0 . Report the value of P⋅Q−1(mod998244353) .
输入输出样例
输入#1
3 3 -1 -1
输出#1
499122179
输入#2
2 1 2
输出#2
0
输入#3
2 -1 -1
输出#3
499122177
说明/提示
In the first example two resulting valid permutations are possible:
- [3,1,2] — 2 inversions;
- [3,2,1] — 3 inversions.
The expected value is 22⋅1+3⋅1=2.5 .
In the second example no −1 are present, thus the only valid permutation is possible — the given one. It has 0 inversions.
In the third example there are two resulting valid permutations — one with 0 inversions and one with 1 inversion.