#abc286a. A - Range Swap

A - Range Swap

Score : 100100 points

问题描述

给定一个长度为 NN 的序列 A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N) 以及四个正整数 P,Q,R,SP,Q,R,S。 这里,P,Q,R,SP,Q,R,S 满足 1PQ<RSN1\leq P\leq Q<R\leq S \leq NQP=SRQ-P=S-R

B=(B1,B2,,BN)B=(B_1, B_2,\ldots, B_N) 为通过交换 AA 中第 PP 到第 QQ 项与第 RR 到第 SS 项所得到的新序列。 输出这个序列 BB

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N) of length NN and positive integers P,Q,RP,Q,R, and SS.
Here, P,Q,RP,Q,R, and SS satisfy 1PQ<RSN1\leq P\leq Q<R\leq S \leq N and QP=SRQ-P=S-R.

Let B=(B1,B2,,BN)B=(B_1, B_2,\ldots, B_N) be the sequence obtained by swapping the PP-th through QQ-th terms and the RR-th through SS-th terms of AA.
Print the sequence BB.

Constraints

  • 1N1001\leq N \leq 100
  • 1Ai1001\leq A_i\leq 100
  • 1PQ<RSN1\leq P\leq Q<R\leq S \leq N
  • QP=SRQ-P=S-R
  • All values in the input are integers.

Input

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

NN PP QQ RR SS

A1A_1 A2A_2 \ldots ANA_N

Output

Print B1,B2,,BNB_1, B_2,\ldots, B_N, with spaces in between.

Sample Input 1

8 1 3 5 7
1 2 3 4 5 6 7 8

Sample Output 1

5 6 7 4 1 2 3 8

Swapping the 11-st through 33-rd terms (1,2,3)(1,2,3) and the 55-th through 77-th terms (5,6,7)(5,6,7) of the sequence A=(1,2,3,4,5,6,7,8)A=(1,2,3,4,5,6,7,8) results in B=(5,6,7,4,1,2,3,8)B=(5,6,7,4,1,2,3,8), which should be printed with spaces in between.

Sample Input 2

5 2 3 4 5
2 2 1 1 1

Sample Output 2

2 1 1 2 1

The same integer may occur multiple times in the sequence.

Sample Input 3

2 1 1 2 2
50 100

Sample Output 3

100 50

Sample Input 4

10 2 4 7 9
22 75 26 45 72 81 47 29 97 2

Sample Output 4

22 47 29 97 72 81 75 26 45 2

update @ 2024/3/10 11:56:57