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)P=(P_1,P_2,\dots,P_N) of (1,2,…,N)(1,2,\dots,N).

For a subsequence x=(x1,x2,…,xk)x=(x_1,x_2,\dots,x_k) of (1,2,…,N)(1,2,\dots,N), let f(x)f(x) denote the sequence obtained by the following procedure.

  • Initialize the sequence Q=(Q1,Q2,…,QN)Q=(Q_1,Q_2,\dots,Q_N) with Q=PQ = P.
  • Let A=(A1,A2,…,Ak)A=(A_1,A_2,\dots,A_k) be the sequence obtained by sorting (Qx1,Qx2,…,Qxk)(Q_{x_1},Q_{x_2},\dots,Q_{x_k}) in ascending order.
  • For every integer ii satisfying 1≤i≤k1 \le i \le k, replace QxiQ_{x_i} with AiA_i. Let f(x)f(x) be QQ at this point.

There are 2N2^N possible choices of xx, including the empty sequence. Find the sum, modulo 998244353998244353, of the number of inversions of f(x)f(x) over all those choices.

给你一个 (1,2,…,N)(1,2,\dots,N) 的排列 P=(P1,P2,…,PN)P=(P_1,P_2,\dots,P_N)。

对于 (1,2,…,N)(1,2,\dots,N) 的任意一个子序列 x=(x1,x2,…,xk)x=(x_1,x_2,\dots,x_k),定义 f(x)f(x) 为按如下步骤得到的序列:

  • 初始化长度为 NN 的序列 Q=(Q1,Q2,…,QN)Q=(Q_1,Q_2,\dots,Q_N),令 Q=PQ = P。
  • 将 (Qx1,Qx2,…,Qxk)(Q_{x_1},Q_{x_2},\dots,Q_{x_k}) 按升序排序,得到序列 A=(A1,A2,…,Ak)A=(A_1,A_2,\dots,A_k)。
  • 对每个满足 1≤i≤k1 \le i \le k 的整数 ii,将 QxiQ_{x_i} 替换为 AiA_i。此时的 QQ 即为 f(x)f(x)。

共有 2N2^N 种可能的 xx(包括空序列)。对所有这些 xx,求 f(x)f(x) 的逆序对数量之和,并对 998244353998244353 取模。

输入格式

The input is given from Standard Input in the following format:

NN
P1 P2 … PNP_1\ P_2\ \dots\ P_N

输入从标准输入中按以下格式给出:

NN
P1 P2 … PNP_1\ P_2\ \dots\ P_N

输出格式

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)f(x) and its number of inversions for all eight possible choices of xx are as follows.

  • For x=()x = (), we have f(x)=(3,1,2)f(x) = (3,1,2), and the number of inversions is 22.
  • For x=(1)x = (1), we have f(x)=(3,1,2)f(x) = (3,1,2), and the number of inversions is 22.
  • For x=(2)x = (2), we have f(x)=(3,1,2)f(x) = (3,1,2), and the number of inversions is 22.
  • For x=(3)x = (3), we have f(x)=(3,1,2)f(x) = (3,1,2), and the number of inversions is 22.
  • For x=(1,2)x = (1,2), we have f(x)=(1,3,2)f(x) = (1,3,2), and the number of inversions is 11.
  • For x=(1,3)x = (1,3), we have f(x)=(2,1,3)f(x) = (2,1,3), and the number of inversions is 11.
  • For x=(2,3)x = (2,3), we have f(x)=(3,1,2)f(x) = (3,1,2), and the number of inversions is 22.
  • For x=(1,2,3)x = (1,2,3), we have f(x)=(1,2,3)f(x) = (1,2,3), and the number of inversions is 00.

Thus, the answer is 2+2+2+2+1+1+2+0=122+2+2+2+1+1+2+0=12.

Constraints

  • 2≤N≤2×1052 \le N \le 2 \times 10^5
  • PP is a permutation of (1,2,…,N)(1,2,\dots,N).
  • All input values are integers.

样例 1 解释:
f(x)f(x) 及其在全部八种可能的 xx 取值下的逆序对数量如下所示。

  • 当 x=()x = () 时,有 f(x)=(3,1,2)f(x) = (3,1,2),逆序对数量为 22。
  • 当 x=(1)x = (1) 时,有 f(x)=(3,1,2)f(x) = (3,1,2),逆序对数量为 22。
  • 当 x=(2)x = (2) 时,有 f(x)=(3,1,2)f(x) = (3,1,2),逆序对数量为 22。
  • 当 x=(3)x = (3) 时,有 f(x)=(3,1,2)f(x) = (3,1,2),逆序对数量为 22。
  • 当 x=(1,2)x = (1,2) 时,有 f(x)=(1,3,2)f(x) = (1,3,2),逆序对数量为 11。
  • 当 x=(1,3)x = (1,3) 时,有 f(x)=(2,1,3)f(x) = (2,1,3),逆序对数量为 11。
  • 当 x=(2,3)x = (2,3) 时,有 f(x)=(3,1,2)f(x) = (3,1,2),逆序对数量为 22。
  • 当 x=(1,2,3)x = (1,2,3) 时,有 f(x)=(1,2,3)f(x) = (1,2,3),逆序对数量为 00。

因此,答案为 2+2+2+2+1+1+2+0=122+2+2+2+1+1+2+0=12。

限制条件

  • 2≤N≤2×1052 \le N \le 2 \times 10^5
  • PP 是 (1,2,…,N)(1,2,\dots,N) 的一个排列。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页