#abc335c. C - Loong Tracking

C - Loong Tracking

Score : 300300 points

问题描述

高桥创造了一个游戏,玩家在游戏中控制坐标平面上的一条龙。

这条龙由 NN 个部分组成,编号从 11NN,其中第 11 个部分被称为 头部

初始状态下,第 ii 个部分位于坐标 (i,0)(i,0)。处理 QQ 个查询,如下所示。

  • 1 C:在方向 CC 上将头部移动 11 个单位。这里,CC 可以是 RLUD,分别代表正 xx 轴方向、负 xx 轴方向、正 yy 轴方向和负 yy 轴方向。除了头部以外的每个部分都会跟随其前面的部分移动。即,第 ii 个部分(2iN2\leq i \leq N)会移动到移动前第 i1i-1 个部分所在的位置。
  • 2 p:找出第 pp 个部分的坐标。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi has created a game where the player controls a dragon on a coordinate plane.

The dragon consists of NN parts numbered 11 to NN, with part 11 being called the head.

Initially, part ii is located at the coordinates (i,0)(i,0). Process QQ queries as follows.

  • 1 C: Move the head by 11 in direction CC. Here, CC is one of R, L, U, and D, which represent the positive xx-direction, negative xx-direction, positive yy-direction, and negative yy-direction, respectively. Each part other than the head moves to follow the part in front of it. That is, part ii (2iN)(2\leq i \leq N) moves to the coordinates where part i1i-1 was before the move.
  • 2 p: Find the coordinates of part pp.

Constraints

  • 2N1062 \leq N \leq 10^6
  • 1Q2×1051 \leq Q \leq 2\times 10^5
  • For the first type of query, CC is one of R, L, U, and D.
  • For the second type of query, 1pN1\leq p \leq N.
  • All numerical input values are integers.

Input

The input is given from Standard Input in the following format:

NN QQ

query1\mathrm{query}_1

\vdots

queryQ\mathrm{query}_Q

Each query is in one of the following two formats:

11 CC

22 pp

Output

Print qq lines, where qq is the number of queries of the second type.
The ii-th line should contain xx and yy separated by a space, where (x,y)(x,y) are the answer to the ii-th such query.

Sample Input 1

5 9
2 3
1 U
2 3
1 R
1 D
2 3
1 L
2 1
2 5

Sample Output 1

3 0
2 0
1 1
1 0
1 0

At each time when processing the second type of query, the parts are at the following positions:

Figure

Note that multiple parts may exist at the same coordinates.

update @ 2024/3/10 01:23:23