Logo
(追記) (追記ここまで)

27185번 - The Tree 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB112252228.571%

문제

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 $c$ colors or be colorless. Initially, all vertices are colorless.

You need to process two types of requests:

  1. color($u,ドル $x$) You are given a vertex $u,ドル paint vertex $u$ with color $x,ドル and then call color($L,ドル $(x + 1) \bmod c$) for its left son $L$ and color($R,ドル $(x - 1 + c) \bmod c$) for its right son $R$. Note that this operation repaints the entire (infinite) set of vertices in the subtree of the vertex $u$. Here $\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 $q,ドル $c$ --- the number of queries and colors, respectively (1ドル \leq q \leq 5 \cdot 10^5,ドル 1ドル \leq c \leq 10^9$). This is followed by $q$ queries, each starts with an integer $t_i$ --- the type of the $i$-th query.

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

If $t_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ドル\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

6 3
1 2
L
2
LL
1 0
LL
2
LLR
2
LR
2
R

예제 출력 1

0
2
1
-1

힌트

출처

Olympiad > Russian Olympiad in Informatics > Russia High School Programming Contest > Russia High School Programming Contest 2022 D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /