33OJ
登录 注册

#P18105. [COCI 2026/2027 #2] Robot

    ID: 20866 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>二分COCI(克罗地亚)2026分类讨论

[COCI 2026/2027 #2] Robot

Problem Description

Robi the robot works in a warehouse shaped like a strip of LL cells, labelled 11 to LL from left to right. Initially, Robi is on cell pp, and each of nn other cells contains exactly one box. The boxes are labelled 11 to nn from left to right, and box ii is initially on cell xix_i.

Robi moves step by step. In one step, he tries to move to the adjacent cell, to the left or to the right of the cell he is on. If that cell contains a box, Robi pushes it in front of him, together with all the boxes that are directly behind it in the direction of movement, with no empty cell between them. Robi and all the boxes he is pushing then move by one cell in the direction of movement.

There is a wall to the left of cell 11 and to the right of cell LL. If, in some step, Robi or one of the boxes he is pushing would have to move past the end of the strip, that step is not performed and nothing moves.

Robi will receive qq commands, one after another, each in one of the following three forms:

  • L d – Robi tries dd times in a row to make a step to the left,
  • D d – Robi tries dd times in a row to make a step to the right,
  • ? j – Robi wants to know on which cell box jj is currently located.

Help Robi and answer all of his questions.

Input Format

The first line contains positive integers LL, nn and qq (2≤L≤10182 \le L \le 10^{18}, 1≤n,q≤200 0001 \le n, q \le 200\,000, n<Ln < L), the number of cells, the number of boxes and the number of commands.

The second line contains a positive integer pp (1≤p≤L1 \le p \le L), the cell on which Robi is initially located.

The third line contains nn positive integers x1,x2,…,xnx_1, x_2, \ldots, x_n (1≤x1<x2<⋯<xn≤L1 \le x_1 < x_2 < \cdots < x_n \le L, xi≠px_i \ne p), the cells on which the boxes are initially located.

Each of the following qq lines contains the description of one command in one of the forms given above. For commands of the form L d and D d it holds that 1≤d≤10181 \le d \le 10^{18}, and for commands of the form ? j it holds that 1≤j≤n1 \le j \le n.

There is at least one command of the form ? j.

Output Format

For each command of the form ? j, in the order in which they are given, output in a separate line the cell on which box jj is located at that moment.

6 1 6
3
5
D 1
? 1
D 1
? 1
D 3
? 1
5
6
6
8 2 8
4
2 6
L 5
? 1
D 3
D 1
? 2
L 2
? 2
? 1
1
7
7
1
10 4 8
4
2 6 7 9
D 3
? 3
D 5
L 10
? 1
? 4
D 2
? 2
9
1
10
8

Hint

Explanation of example 1

Robi is on cell 33, and the only box is on cell 55. After the first command, Robi is on cell 44, right next to the box, which has not moved yet. With the second command, Robi moves to cell 55 and pushes the box to cell 66. The box is now next to the wall, so Robi cannot make any step with the third command.

Explanation of example 2

With the first command, Robi reaches box 11 after one step and pushes it to cell 11 in the next step. The box is then next to the wall, so Robi cannot make the remaining three steps and stays on cell 22. With the command D 3, Robi moves to cell 55, right next to box 22, and with the command D 1 he pushes it to cell 77. With the command L 2, Robi returns to cell 44, while the boxes stay where they are.

Scoring

Subtask Points Constraints
1 9 n=1n = 1
2 14 n,q≤2000n, q \le 2000
3 16 Initially, all boxes are to the right of Robi, i.e. p<x1p < x_1.
4 31 No additional constraints.