Sequence and Shift Queries

Interview

Time limit1sMemory limit256 MB

Summary
Maintain a sequence under point additions and cyclic rotations by s positions to the right or left, then print the final array.
Level

Medium4 of 10

Topics
Array, Implementation, Math, Simulation
Solved
No attempts yet

Problem

You are given an integer sequence [a1, a2, ..., aN] of length N. Write a program that performs the following operations in order and then prints the sequence.

  • 1 i x : add the integer x to ai.
  • 2 s : shift the sequence right by s positions.
  • 3 s : shift the sequence left by s positions.

Shifting the sequence right by one position turns [a1, a2, …, aN-1, aN] into [aN, a1, a2, …, aN-1].

Shifting the sequence left by one position turns [a1, a2, …, aN-1, aN] into [a2, …, aN-1, aN, a1].

Jinsu wrote code that runs a loop N times for every shift operation, submitted it, and got a time limit exceeded verdict.

Input

The first line gives the length of the sequence N (2 ≤ N ≤ 200,000) and the number of operations Q (1 ≤ Q ≤ 200,000).

The second line gives the integers a1, a2, ..., aN (-10,000 ≤ ai ≤ 10,000).

The next Q lines each contain one operation.

Output

On the first line, print a1, a2, …, aN after performing the Q operations in order, separated by spaces.

Constraints

  • 1 ≤ i ≤ N
  • -10,000 ≤ x ≤ 10,000
  • 1 ≤ s ≤ N-1

Examples1

  1. Example 1

    Input
    5 4
    1 2 3 4 5
    1 1 4
    2 3
    1 2 2
    3 1
    
    Expected output
    6 5 5 2 3