#P6148. [USACO20FEB] Swapity Swapity Swap S

[USACO20FEB] Swapity Swapity Swap S

Description

Farmer John’s NN cows (1N1051\leq N\leq 10^5) are standing in a line. For each 1iN1\leq i\leq N, the ID of the ii-th cow from left to right is ii.

Farmer John has come up with a new morning exercise plan for the cows. He gives the cows MM pairs of integers (L1,R1)(LM,RM)(L_1,R_1)\ldots (L_M,R_M), where 1M1001\leq M\leq 100. He asks them to repeat the following process, which consists of MM steps, a total of KK times (1K1091\leq K\leq 10^9):

For each ii from 11 to MM:

  • Reverse the order of the cows currently in positions LiRiL_i\ldots R_i from left to right.
  • After the cows repeat this process KK times, output, for each 1iN1\leq i\leq N, the ID of the ii-th cow from left to right.

Input Format

The first line contains NN, MM, and KK. For each 1iM1\leq i\leq M, line i+1i+1 contains LiL_i and RiR_i, both integers in the range 1N1\ldots N, with Li<RiL_i<R_i.

Output Format

On line ii, output the ID of the ii-th element (from left to right) in the cow sequence after the instruction sequence has been executed KK times.

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

Hint

Sample Explanation:

Initially, the cows are ordered from left to right as [1,2,3,4,5,6,71,2,3,4,5,6,7]. After the first step of this process, the order becomes [1,5,4,3,2,6,71,5,4,3,2,6,7]. After the second step of this process, the order becomes [1,5,7,6,2,3,41,5,7,6,2,3,4]. Repeating these two steps one more time each gives the sample output.

Subtasks:

  • Test case 22 satisfies N=K=100N=K=100.
  • Test cases 33-55 satisfy K103K\leq 10^3.
  • Test cases 66-1010 have no additional constraints.

Translated by ChatGPT 5