102860: [AtCoder]ABC286 A - Range Swap

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:1 Solved:0

Description

Score : $100$ points

Problem Statement

You are given a sequence $A=(A_1,A_2,\ldots,A_N)$ of length $N$ and positive integers $P,Q,R$, and $S$.
Here, $P,Q,R$, and $S$ satisfy $1\leq P\leq Q<R\leq S \leq N$ and $Q-P=S-R$.

Let $B=(B_1, B_2,\ldots, B_N)$ be the sequence obtained by swapping the $P$-th through $Q$-th terms and the $R$-th through $S$-th terms of $A$.
Print the sequence $B$.

Constraints

  • $1\leq N \leq 100$
  • $1\leq A_i\leq 100$
  • $1\leq P\leq Q<R\leq S \leq N$
  • $Q-P=S-R$
  • All values in the input are integers.

Input

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

$N$ $P$ $Q$ $R$ $S$
$A_1$ $A_2$ $\ldots$ $A_N$

Output

Print $B_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 $1$-st through $3$-rd terms $(1,2,3)$ and the $5$-th through $7$-th terms $(5,6,7)$ of the sequence $A=(1,2,3,4,5,6,7,8)$ results in $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

Input

题意翻译

给定一个长度为 $n$ 的序列 $a$,将从第 $p$ 项到第 $q$ 项与从第 $r$ 项到第 $s$ 项的元素交换,求交换后的结果。 保证 $1\le n \le 100$,$1\le a_i \le 100$,$1 \le p \le q < r \le s \le n$,$q-p=s-r$。 翻译提供者:@\_\_Allen\_123\_\_

Output

分数:100分

问题描述

你被给定一个长度为$N$的序列$A=(A_1,A_2,\ldots,A_N)$,以及正整数$P, Q, R$和$S$。

其中,$P, Q, R$和$S$满足$1\leq P\leq Q<R\leq S \leq N$且$Q-P=S-R$。

令$B=(B_1, B_2,\ldots, B_N)$为通过交换$A$的第$P$个到第$Q$个项和第$R$个到第$S$个项得到的序列。

打印序列$B$。

约束条件

  • $1\leq N \leq 100$
  • $1\leq A_i\leq 100$
  • $1\leq P\leq Q<R\leq S \leq N$
  • $Q-P=S-R$
  • 输入中的所有值都是整数。

输入

输入从标准输入按以下格式给出:

$N$ $P$ $Q$ $R$ $S$
$A_1$ $A_2$ $\ldots$ $A_N$

输出

打印$B_1, B_2,\ldots, B_N$,中间用空格隔开。


样例输入1

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

样例输出1

5 6 7 4 1 2 3 8

交换序列$A=(1,2,3,4,5,6,7,8)$的第$1$个到第$3$个项$(1,2,3)$和第$5$个到第$7$个项$(5,6,7)$, 得到$B=(5,6,7,4,1,2,3,8)$,应该用空格隔开打印。


样例输入2

5 2 3 4 5
2 2 1 1 1

样例输出2

2 1 1 2 1

序列中可以多次出现相同的整数。


样例输入3

2 1 1 2 2
50 100

样例输出3

100 50

样例输入4

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

样例输出4

22 47 29 97 72 81 75 26 45 2

加入题单

算法标签: