AT_arc218_e.Reverse and Reverse

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For a permutation p=(p1,p2,…,pN)p=(p_1,p_2,\dots,p_N) of (1,2,…,N)(1,2,\dots,N) and a positive integer MM, let f(p,M)f(p,M) denote the answer to the following problem.

Perform the following operation MM times on pp.

  • Choose an integer ii with 1≤i≤N−11 \le i \le N-1, and reverse each of (p1,p2,…,pi)(p_1,p_2,\dots,p_i) and (pi+1,pi+2,…,pN)(p_{i+1},p_{i+2},\dots,p_N). Formally, replace pp with (pi,pi−1,…,p1,pN,pN−1,…,pi+1)(p_i,p_{i-1},\dots,p_1,p_N,p_{N-1},\dots,p_{i+1}).

There are (N−1)M(N-1)^M possible sequences of operations. Find the sum, modulo 998244353998244353, of "the number of inversions of pp after MM operations" over all such sequences.

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). Process the following query QQ times.

  • You are given an integer xx with 1≤x≤N−11 \le x \le N-1 and a positive integer KK. Swap PxP_x and Px+1P_{x+1}. Then, find f(P,K)f(P,K).

对于 (1,2,…,N)(1,2,\dots,N) 的一个排列 p=(p1,p2,…,pN)p=(p_1,p_2,\dots,p_N) 和一个正整数 MM,记 f(p,M)f(p,M) 为如下问题的答案:

对 pp 执行以下操作 MM 次:

  • 选择一个满足 1≤i≤N−11 \le i \le N-1 的整数 ii,并将 (p1,p2,…,pi)(p_1,p_2,\dots,p_i) 和 (pi+1,pi+2,…,pN)(p_{i+1},p_{i+2},\dots,p_N) 分别翻转。形式上,将 pp 替换为 (pi,pi−1,…,p1,pN,pN−1,…,pi+1)(p_i,p_{i-1},\dots,p_1,p_N,p_{N-1},\dots,p_{i+1})。

共有 (N−1)M(N-1)^M 种可能的操作序列。对所有这些操作序列,求“执行 MM 次操作后 pp 的逆序对数量”的总和,并对 998244353998244353 取模。

给定 (1,2,…,N)(1,2,\dots,N) 的一个排列 P=(P1,P2,…,PN)P=(P_1,P_2,\dots,P_N)。接下来处理 QQ 次查询。

  • 每次查询给出一个满足 1≤x≤N−11 \le x \le N-1 的整数 xx 和一个正整数 KK。交换 PxP_x 与 Px+1P_{x+1},然后计算 f(P,K)f(P,K)。

输入格式

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

NN QQ
P1 P2 … PNP_1\ P_2\ \dots\ P_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

Each query is given in the following format:

xx KK

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

NN QQ
P1 P2 … PNP_1\ P_2\ \dots\ P_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

每个查询按以下格式给出:

xx KK

输出格式

Output QQ lines. The ii-th line should contain the answer to queryi\mathrm{query}_i.

输出 QQ 行。第 ii 行应包含 queryi\mathrm{query}_i 的答案。

输入输出样例

  • 输入#1

    3 2
    1 3 2
    1 1
    2 1

    输出#1

    4
    4
  • 输入#2

    4 4
    3 2 4 1
    2 1
    2 2
    3 3
    1 4

    输出#2

    11
    28
    67
    242
  • 输入#3

    10 7
    7 9 3 10 5 2 4 6 8 1
    2 29
    1 86
    3 30
    8 64
    1 24
    1 9
    5 55

    输出#3

    29362950
    633265500
    847469581
    741165544
    385334408
    653522086
    169485402

说明/提示

Sample 1 Explanation:
For the first query, swapping P1P_1 and P2P_2 gives P=(3,1,2)P=(3,1,2). There are two possible sequences of operations as follows:

  • Choose i=1i = 1. PP becomes (3,2,1)(3,2,1). The number of inversions is 33.
  • Choose i=2i = 2. PP becomes (1,3,2)(1,3,2). The number of inversions is 11.

Thus, the answer is 3+1=43+1=4.

For the second query, swapping P2P_2 and P3P_3 gives P=(3,2,1)P=(3,2,1). There are two possible sequences of operations as follows:

  • Choose i=1i = 1. PP becomes (3,1,2)(3,1,2). The number of inversions is 22.
  • Choose i=2i = 2. PP becomes (2,3,1)(2,3,1). The number of inversions is 22.

Thus, the answer is 2+2=42+2=4.

Constraints

  • 2≤N≤2×1052 \le N \le 2 \times 10^5
  • 1≤Q≤2×1051 \le Q \le 2 \times 10^5
  • PP is a permutation of (1,2,…,N)(1,2,\dots,N).
  • 1≤x≤N−11 \le x \le N-1
  • 1≤K≤1091 \le K \le 10^9
  • All input values are integers.

样例 1 解释:
对于第一个查询,交换 P1P_1 和 P2P_2 后得到 P=(3,1,2)P=(3,1,2)。存在如下两种可能的操作序列:

  • 选择 i=1i = 1,则 PP 变为 (3,2,1)(3,2,1),此时逆序对数量为 33;
  • 选择 i=2i = 2,则 PP 变为 (1,3,2)(1,3,2),此时逆序对数量为 11。

因此,答案为 3+1=43+1=4。

对于第二个查询,交换 P2P_2 和 P3P_3 后得到 P=(3,2,1)P=(3,2,1)。存在如下两种可能的操作序列:

  • 选择 i=1i = 1,则 PP 变为 (3,1,2)(3,1,2),此时逆序对数量为 22;
  • 选择 i=2i = 2,则 PP 变为 (2,3,1)(2,3,1),此时逆序对数量为 22。

因此,答案为 2+2=42+2=4。

约束条件

  • 2≤N≤2×1052 \le N \le 2 \times 10^5
  • 1≤Q≤2×1051 \le Q \le 2 \times 10^5
  • PP 是 (1,2,…,N)(1,2,\dots,N) 的一个排列。
  • 1≤x≤N−11 \le x \le N-1
  • 1≤K≤1091 \le K \le 10^9
  • 所有输入值均为整数。

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

首页