AT_abc476_e.Min-Max Swap
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a permutation P=(P1,P2,…,PN) of (1,2,…,N) and length-M integer sequences L=(L1,L2,…,LM) and R=(R1,R2,…,RM).
For this permutation P, perform the following operation for i=1,2,…,M in this order:
- Among PLi,PLi+1,…,PRi, swap the positions of the element with the minimum value and the element with the maximum value.
Find each element of P after the M operations.
给你一个 (1,2,…,N) 的排列 P=(P1,P2,…,PN),以及两个长度为 M 的整数序列 L=(L1,L2,…,LM) 和 R=(R1,R2,…,RM)。
对这个排列 P,按 i=1,2,…,M 的顺序依次执行以下操作:
- 在子数组 PLi,PLi+1,…,PRi 中,将最小值元素与最大值元素的位置互换。
求经过 M 次操作后 P 的每个元素。
输入格式
The input is given from Standard Input in the following format:
N M
P1 P2 … PN
L1 R1
L2 R2
⋮
LM RM
输入从标准输入中按以下格式给出:
N M
P1 P2 … PN
L1 R1
L2 R2
⋮
LM RM
输出格式
Output each element of P after the M operations, in order from front to back, separated by spaces.
在执行 M 次操作后,按从前到后的顺序输出 P 的每个元素,元素之间用空格分隔。
输入输出样例
输入#1
5 3 3 1 4 2 5 1 3 1 5 1 4
输出#1
3 4 2 5 1
输入#2
6 7 3 6 5 2 4 1 4 5 2 3 3 5 4 6 3 4 1 6 3 5
输出#2
3 5 4 6 2 1
说明/提示
Sample 1 Explanation:
Initially, P=(3,1,4,2,5).
- For i=1: among P1,P2,P3, the minimum value is P2 and the maximum value is P3. Swapping P2 and P3 gives P=(3,4,1,2,5).
- For i=2: among P1,P2,P3,P4,P5, the minimum value is P3 and the maximum value is P5. Swapping P3 and P5 gives P=(3,4,5,2,1).
- For i=3: among P1,P2,P3,P4, the minimum value is P4 and the maximum value is P3. Swapping P3 and P4 gives P=(3,4,2,5,1).
After the three operations, P=(3,4,2,5,1).
Constraints
- 2≤N≤2×105
- 1≤M≤2×105
- P is a permutation of (1,2,…,N).
- 1≤Li<Ri≤N
- All input values are integers.
样例 1 解释:
初始时,P=(3,1,4,2,5)。
- 对于 i=1:在 P1,P2,P3 中,最小值为 P2,最大值为 P3。交换 P2 和 P3 后得到 P=(3,4,1,2,5)。
- 对于 i=2:在 P1,P2,P3,P4,P5 中,最小值为 P3,最大值为 P5。交换 P3 和 P5 后得到 P=(3,4,5,2,1)。
- 对于 i=3:在 P1,P2,P3,P4 中,最小值为 P4,最大值为 P3。交换 P3 和 P4 后得到 P=(3,4,2,5,1)。
经过三次操作后,P=(3,4,2,5,1)。
约束条件
- 2≤N≤2×105
- 1≤M≤2×105
- P 是 (1,2,…,N) 的一个排列。
- 1≤Li<Ri≤N
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?