Under construction

Still being built. Things may change

Tree and Queries 16

Time limit8sMemory limit512 MB

Summary
Edges are added to a forest online, and each type 2 query takes a vertex u and an integer k, but the statement never defines the query answer.
Level

Hard8 of 10

Topics
Tree, Graph
Solved
No attempts yet

Problem

There is a forest of NN vertices. The vertices are numbered from 1 to NN. The initial forest has no edges.

Input

The first line contains two integers NN and QQ. (1≤N≤100 0001 \le N \le 100\,000, 1≤Q≤200 0001 \le Q \le 200\,000)

Each of the next QQ lines contains three integers tit_i, aia_i, bib_i. (1≤ti≤21 \le t_i \le 2, 0≤ai,bi<n0 \le a_i, b_i < n)

Consider an extra variable lastlast, which starts at 0.

  • If ti=1t_i = 1, the arguments are ui=((ai+last)mod  n)+1u_i = ((a_i + last) \mod n) + 1 and vi=((bi+last)mod  n)+1v_i = ((b_i + last) \mod n) + 1.
  • If ti=2t_i = 2, the arguments are ui=((ai+last)mod  n)+1u_i = ((a_i + last) \mod n) + 1 and ki=((bi+last)mod  n)k_i = ((b_i + last) \mod n). After computing the answer to this query, set lastlast to that answer.

Output

For each query with ti=2t_i = 2, print the answer on its own line.

Examples1

  1. Example 1

    Input
    7 9
    1 0 6
    1 4 3
    1 0 5
    1 1 2
    1 3 1
    1 4 5
    2 2 3
    2 2 1
    2 0 0
    
    Expected output
    1
    2
    1