AT_arc218_e.Reverse and Reverse
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For a permutation p=(p1,p2,…,pN) of (1,2,…,N) and a positive integer M, let f(p,M) denote the answer to the following problem.
Perform the following operation M times on p.
- Choose an integer i with 1≤i≤N−1, and reverse each of (p1,p2,…,pi) and (pi+1,pi+2,…,pN). Formally, replace p with (pi,pi−1,…,p1,pN,pN−1,…,pi+1).
There are (N−1)M possible sequences of operations. Find the sum, modulo 998244353, of "the number of inversions of p after M operations" over all such sequences.
You are given a permutation P=(P1,P2,…,PN) of (1,2,…,N). Process the following query Q times.
- You are given an integer x with 1≤x≤N−1 and a positive integer K. Swap Px and Px+1. Then, find f(P,K).
对于 (1,2,…,N) 的一个排列 p=(p1,p2,…,pN) 和一个正整数 M,记 f(p,M) 为如下问题的答案:
对 p 执行以下操作 M 次:
- 选择一个满足 1≤i≤N−1 的整数 i,并将 (p1,p2,…,pi) 和 (pi+1,pi+2,…,pN) 分别翻转。形式上,将 p 替换为 (pi,pi−1,…,p1,pN,pN−1,…,pi+1)。
共有 (N−1)M 种可能的操作序列。对所有这些操作序列,求“执行 M 次操作后 p 的逆序对数量”的总和,并对 998244353 取模。
给定 (1,2,…,N) 的一个排列 P=(P1,P2,…,PN)。接下来处理 Q 次查询。
- 每次查询给出一个满足 1≤x≤N−1 的整数 x 和一个正整数 K。交换 Px 与 Px+1,然后计算 f(P,K)。
输入格式
The input is given from Standard Input in the following format:
N Q
P1 P2 … PN
query1
query2
⋮
queryQ
Each query is given in the following format:
x K
输入从标准输入中按以下格式给出:
N Q
P1 P2 … PN
query1
query2
⋮
queryQ
每个查询按以下格式给出:
x K
输出格式
Output Q lines. The i-th line should contain the answer to queryi.
输出 Q 行。第 i 行应包含 queryi 的答案。
输入输出样例
输入#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 P1 and P2 gives P=(3,1,2). There are two possible sequences of operations as follows:
- Choose i=1. P becomes (3,2,1). The number of inversions is 3.
- Choose i=2. P becomes (1,3,2). The number of inversions is 1.
Thus, the answer is 3+1=4.
For the second query, swapping P2 and P3 gives P=(3,2,1). There are two possible sequences of operations as follows:
- Choose i=1. P becomes (3,1,2). The number of inversions is 2.
- Choose i=2. P becomes (2,3,1). The number of inversions is 2.
Thus, the answer is 2+2=4.
Constraints
- 2≤N≤2×105
- 1≤Q≤2×105
- P is a permutation of (1,2,…,N).
- 1≤x≤N−1
- 1≤K≤109
- All input values are integers.
样例 1 解释:
对于第一个查询,交换 P1 和 P2 后得到 P=(3,1,2)。存在如下两种可能的操作序列:
- 选择 i=1,则 P 变为 (3,2,1),此时逆序对数量为 3;
- 选择 i=2,则 P 变为 (1,3,2),此时逆序对数量为 1。
因此,答案为 3+1=4。
对于第二个查询,交换 P2 和 P3 后得到 P=(3,2,1)。存在如下两种可能的操作序列:
- 选择 i=1,则 P 变为 (3,1,2),此时逆序对数量为 2;
- 选择 i=2,则 P 变为 (2,3,1),此时逆序对数量为 2。
因此,答案为 2+2=4。
约束条件
- 2≤N≤2×105
- 1≤Q≤2×105
- P 是 (1,2,…,N) 的一个排列。
- 1≤x≤N−1
- 1≤K≤109
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?