13472 - KYてぇてぇ — Birthday Present(class + reverse)   

Description

Kuo-chan is given a sequence A and a constant K as his birthday present from Yang-chan.

Kuo-chan is allowed to perfrom the following operation:

  1. push x — push x to the tail of A
  2. pop — remove the median value of A (the median value of A is A[ (|A|+1)/2 ], with index start at 1)
  3. programming tanoshi — for every element a in A, assign a % K to a
  4. reverse — reverse the whole A, the head becomes the tail and the tail becomes the head

 

Whenever performing pop operation, the length of A is guaranteed to be odd, hence A won't be empty.

 

For example, if A = [4, 3, 5], K = 2

push 11 ► A = [4, 3, 5, 11]

reverse ► A = [11, 5, 3, 4]

push 7 ► A = [11, 5, 3, 4, 7]

pop ► A = [11, 5, 4, 7]

programming tanoshi ► A = [1, 1, 0, 1] 

 

Yang-chan is curious about what A is after Kuo-chan performs some operations to it.

Help him find it out!

 

(Remember to include function.h in your function.cpp file.)

 

Input

The first line contains three integers N K Q — the length of A, the constant Yang-chan gives Kuo-chan, the number of operations Kuo-chan performs.

The second line contains N integers a1, a2, ..., aN (1 <= ai <= N) — the elements of A. 

Each of the next Q lines describes the operations. Each line is one of three types:

  1. push x (1 <= x <= 10000)
  2. pop
  3. programming tanoshi
  4. reverse

 

Different testcases have different constraints.

  1. N <= 103, Q <= 2N, K <= 4000, operations: {pop, push}
  2. N <= 103, Q <= 2N, K <= 4000, operations: {pop, push, programming tanoshi}
  3. N <= 105, Q <= 2N, K <= 4000, operations: {pop, push}
  4. N <= 105, Q <= 2N, K <= 4000, operations: {pop, push, programming tanoshi}
  5. N <= 105, Q <= 3N, K <= 4000, operations: {pop, push, programming tanoshi, reverse}
  6. N <= 105, Q <= 3N, K <= 4000, operations: {pop, push, programming tanoshi, reverse}

 

Output

You should print one line containing the elements of A after the operations. For 1 <= i <= |A|, the i-th number should be A[ i ].

Sample Input  Download

Sample Output  Download

Partial Judge Code

13472.cpp

Partial Judge Header

13472.h

Tags




Discuss