#B. 排序(sort)

    Type: RemoteJudge 1000ms 250MiB

排序(sort)

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

巡给你一个 1n1\sim n 的排列 pp,维护两种操作:

  • 1 x 交换 px,px+1p_x,p_{x+1}
  • 2 x 求出当前排列经过 xx 轮冒泡排序后的逆序对个数。

对一个长度为 nn 的排列 pip_i 进行一轮冒泡排序的伪代码如下:

for(int i=1;i<n;i++) 
    if(a[i]>a[i+1]) 
        swap(a[i],a[i+1]);

输入格式

第一行两个整数 nnmm,表示排列长度与操作个数。

第二行 nn 个整数表示排列 pip_i

接下来 mm 行每行两个整数 oi,xio_i,x_i,描述一次操作。

输出格式

对于每次询问操作输出一行一个整数表示答案。

样例

【样例输入】

3 6
1 2 3
2 0
1 1
1 2
2 0
2 1
2 2

【样例输出】

0
2
1
0

数据范围

对于测试点 121 ∼ 2n,m100n,m \leq 100

对于测试点 343 ∼ 4n,m2000n,m \leq 2000

对于测试点 565 ∼ 6:交换操作个数不超过 100100

对于所有测试点:2n,m2×1052 \leq n,m \leq 2 \times 10^5oi{1,2}o_i \in \{1,2\}

  • oi=1o_i=1,则 1x<n1\leq x< n
  • 否则,0x23210\leq x\leq 2^{32}-1.

NOIP 模拟赛(十一)

Not Attended
Status
Done
Rule
OI
Problem
4
Start at
2024-11-20 7:45
End at
2024-11-20 12:15
Duration
4.5 hour(s)
Host
Partic.
17