아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

The Tree

시간 제한1초메모리 제한1024 MB

요약
무한 이진 트리에서 방향과 깊이에 따라 색이 정해지는 부분 트리 칠하기 연산을 처리하고, 특정 정점의 현재 색을 답한다.
난이도

보통10점 중 7점

유형
트리, 누적 합, 구현, 수학
정답자
아직 제출이 없습니다

문제

You are given an infinite binary tree. The tree has the root and infinitely many vertices, each vertex has left son and right son, each vertex except the root has a parent.

Every vertex can be painted in one of cc colors or be colorless. Initially, all vertices are colorless.

You need to process two types of requests:

  1. color(uu, xx) You are given a vertex uu, paint vertex uu with color xx, and then call color(LL, (x+1) mod c(x + 1) \bmod c) for its left son LL and color(RR, (x−1+c) mod c(x - 1 + c) \bmod c) for its right son RR. Note that this operation repaints the entire (infinite) set of vertices in the subtree of the vertex uu. Here  mod \bmod is the operation of taking a division remainder. If the vertex has already been painted, then its color changes to the new one.
  2. Given a vertex, output its current color.

입력

The first line contains two integers qq, cc --- the number of queries and colors, respectively (1≤q≤5⋅1051 \leq q \leq 5 \cdot 10^5, 1≤c≤1091 \leq c \leq 10^9). This is followed by qq queries, each starts with an integer t_it\_i --- the type of the ii-th query.

If t_it\_i = 1, then an integer xx (0≤x≤c−10 \leq x \leq c - 1) is given in the line, the color that the vertex of the query uu should be colored. The next line describes the path to the vertex uu in the form of a non-empty string s_is\_i consisting of the characters 'L' and 'R'. This string specifies the path from the root of the tree to the vertex uu, where 'L' denotes going to the left son, and 'R' --- going to the right son.

If t_it\_i = 2, then the next line specifies the path to the vertex whose color should be output, described similarly to the previous query.

It is guaranteed that the sum of the lengths of the paths to all the vertices of the queries does not exceed 5⋅1055\cdot 10^5.

출력

For each request of the second type print the color of the corresponding vertex on a separate line. If the vertex is colorless, print −1-1.

예제1

  1. 예제 1

    입력
    6 3
    1 2
    L
    2
    LL
    1 0
    LL
    2
    LLR
    2
    LR
    2
    R
    
    예상 출력
    0
    2
    1
    -1