最小值-最大值交换AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given a permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\ldots,N)$ and length-$M$ integer sequences $L=(L_1,L_2,\ldots,L_M)$ and $R=(R_1,R_2,\ldots,R_M)$.
给定一个 $(1,2,\ldots,N)$ 的排列 $P=(P_1,P_2,\ldots,P_N)$,以及两个长度为 $M$ 的整数序列 $L=(L_1,L_2,\ldots,L_M)$ 和 $R=(R_1,R_2,\ldots,R_M)$。AI (CI翻译)
For this permutation $P$, perform the following operation for $i=1,2,\ldots,M$ in this order:
对于排列 $P$,按顺序对 $i=1,2,\ldots,M$ 执行以下操作:AI (CI翻译)
- Among
$P_{L_i},P_{L_i+1},\ldots,P_{R_i}$, swap the positions of the element with the minimum value and the element with the maximum value.
- 在
$P_{L_i},P_{L_i+1},\ldots,P_{R_i}$中,交换最小值元素与最大值元素的位置。
Find each element of $P$ after the $M$ operations.
求经过 $M$ 次操作后,$P$ 中的每个元素。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$2\le N\le 2\times 10^5$$1\le M\le 2\times 10^5$$P$is a permutation of$(1,2,\ldots,N)$.$1\le L_i < R_i\le N$- All input values are integers.
$2\le N\le 2\times 10^5$$1\le M\le 2\times 10^5$$P$是$(1,2,\ldots,N)$的一个排列。$1\le L_i < R_i\le N$- 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
N M
P_1 P_2 \ldots P_N
L_1 R_1
L_2 R_2
\vdots
L_M R_M
N M
P_1 P_2 \ldots P_N
L_1 R_1
L_2 R_2
\vdots
L_M R_MAI (CI翻译)
Output
输出格式
AI (CI翻译)Output each element of $P$ after the $M$ operations, in order from front to back, separated by spaces.
按从前到后的顺序输出经过 $M$ 次操作后 $P$ 中的每个元素,相邻元素之间用空格分隔。AI (CI翻译)
样例
5 3
3 1 4 2 5
1 3
1 5
1 4
3 4 2 5 1
6 7
3 6 5 2 4 1
4 5
2 3
3 5
4 6
3 4
1 6
3 5
3 5 4 6 2 1
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。