Magical Disk and Cards#9093

Magical Disk and Cards

1 секунда
64 мегабајти
Многу тешко

Cossack Vus has long known the New Top Secret of the Lady, but he still enjoys playing the games she offers. This time, the Lady wants to teach Cossack Vus how to perform magical operations on a disk.

The disk is a circle divided into equal segments. On the front side of the disk, numbers from to are written sequentially in a clockwise direction, with one number in each segment. On the back side, numbers from to are written sequentially in a counterclockwise direction, with one number in each segment. In each segment, the numbers on opposite sides are the same but with opposite signs. The number is positioned in the top sector.

H1.jpg

Figure 1 shows the front side of the disk, and Figure 2 shows the back side. The top sector is highlighted in gray.

There is also a deck of cards. Each card has a number written on it, which does not exceed 10^9 in absolute value. In one move, the Lady reviews all the cards from start to finish in sequence. Let the number on the current card be . If a > 0, the disk rotates clockwise by segments. If a < 0, the disk rotates counterclockwise by segments. If a = 0, the disk flips from the front side to the back or from the back to the front, keeping the sector that was on top in its place.

Given the initial information about the numbers on cards and operations, in each of which two cards need to be swapped, the Lady makes one move with the resulting deck of cards. Cossack Vus must determine the number that will be on the top sector on the visible side after this move. Help Cossack Vus find the number in the top sector after each move. Note that before each new move, the disk returns to its initial position, where the number is in the top sector.

Влез

The first line contains three integers , , and (1 \leq k \leq 10^9,\ 2 \leq n \leq 10^5,\ 1 \leq q \leq 10^5) — the number of sectors, cards in the deck, and operations, respectively.

The second line contains integers a_1, a_2, ..., a_n (-10^9 \leq a_i \leq 10^9) — the value of the -th card from the top of the deck.

The next lines contain two integers and (1 \leq x < y \leq n) — the positions of the cards that need to be swapped during the corresponding operation.

Излез

For each operation, output one number on a separate line — the answer to the problem after performing the current operation.

Примери

Пример 1

Loading
Loading

Пример 2

Loading
Loading

Забелешка

Explanation for the first example:

After performing the swap operation, the deck of cards looks like this: , , , . Initially, the number is in the top sector. Then the Lady takes the card , and now the number is on top. After the card , the number is on top, after the next zero, the number is on top, and after the last card , the number is on top. The image below illustrates this process.

H2.jpg