AT_arc228_c.Partially Sort
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a permutation P=(P1,P2,…,PN) of (1,2,…,N).
For a subsequence x=(x1,x2,…,xk) of (1,2,…,N), let f(x) denote the sequence obtained by the following procedure.
- Initialize the sequence Q=(Q1,Q2,…,QN) with Q=P.
- Let A=(A1,A2,…,Ak) be the sequence obtained by sorting (Qx1,Qx2,…,Qxk) in ascending order.
- For every integer i satisfying 1≤i≤k, replace Qxi with Ai. Let f(x) be Q at this point.
There are 2N possible choices of x, including the empty sequence. Find the sum, modulo 998244353, of the number of inversions of f(x) over all those choices.
给你一个 (1,2,…,N) 的排列 P=(P1,P2,…,PN)。
对于 (1,2,…,N) 的任意一个子序列 x=(x1,x2,…,xk),定义 f(x) 为按如下步骤得到的序列:
- 初始化长度为 N 的序列 Q=(Q1,Q2,…,QN),令 Q=P。
- 将 (Qx1,Qx2,…,Qxk) 按升序排序,得到序列 A=(A1,A2,…,Ak)。
- 对每个满足 1≤i≤k 的整数 i,将 Qxi 替换为 Ai。此时的 Q 即为 f(x)。
共有 2N 种可能的 x(包括空序列)。对所有这些 x,求 f(x) 的逆序对数量之和,并对 998244353 取模。
输入格式
The input is given from Standard Input in the following format:
N
P1 P2 … PN
输入从标准输入中按以下格式给出:
N
P1 P2 … PN
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
3 3 1 2
输出#1
12
输入#2
5 4 2 5 3 1
输出#2
148
输入#3
13 2 7 4 9 3 13 8 12 6 5 10 11 1
输出#3
174080
说明/提示
Sample 1 Explanation:
f(x) and its number of inversions for all eight possible choices of x are as follows.
- For x=(), we have f(x)=(3,1,2), and the number of inversions is 2.
- For x=(1), we have f(x)=(3,1,2), and the number of inversions is 2.
- For x=(2), we have f(x)=(3,1,2), and the number of inversions is 2.
- For x=(3), we have f(x)=(3,1,2), and the number of inversions is 2.
- For x=(1,2), we have f(x)=(1,3,2), and the number of inversions is 1.
- For x=(1,3), we have f(x)=(2,1,3), and the number of inversions is 1.
- For x=(2,3), we have f(x)=(3,1,2), and the number of inversions is 2.
- For x=(1,2,3), we have f(x)=(1,2,3), and the number of inversions is 0.
Thus, the answer is 2+2+2+2+1+1+2+0=12.
Constraints
- 2≤N≤2×105
- P is a permutation of (1,2,…,N).
- All input values are integers.
样例 1 解释:
f(x) 及其在全部八种可能的 x 取值下的逆序对数量如下所示。
- 当 x=() 时,有 f(x)=(3,1,2),逆序对数量为 2。
- 当 x=(1) 时,有 f(x)=(3,1,2),逆序对数量为 2。
- 当 x=(2) 时,有 f(x)=(3,1,2),逆序对数量为 2。
- 当 x=(3) 时,有 f(x)=(3,1,2),逆序对数量为 2。
- 当 x=(1,2) 时,有 f(x)=(1,3,2),逆序对数量为 1。
- 当 x=(1,3) 时,有 f(x)=(2,1,3),逆序对数量为 1。
- 当 x=(2,3) 时,有 f(x)=(3,1,2),逆序对数量为 2。
- 当 x=(1,2,3) 时,有 f(x)=(1,2,3),逆序对数量为 0。
因此,答案为 2+2+2+2+1+1+2+0=12。
限制条件
- 2≤N≤2×105
- P 是 (1,2,…,N) 的一个排列。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?