CF1525C.Robot Collisions

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn robots driving along an OX axis. There are also two walls: one is at coordinate 00 and one is at coordinate mm.

The ii-th robot starts at an integer coordinate xi (0<xi<m)x_i~(0 \lt x_i \lt m) and moves either left (towards the 00) or right with the speed of 11 unit per second. No two robots start at the same coordinate.

Whenever a robot reaches a wall, it turns around instantly and continues his ride in the opposite direction with the same speed.

Whenever several robots meet at the same integer coordinate, they collide and explode into dust. Once a robot has exploded, it doesn't collide with any other robot. Note that if several robots meet at a non-integer coordinate, nothing happens.

For each robot find out if it ever explodes and print the time of explosion if it happens and −1-1 otherwise.

有 nn 个机器人沿 OXOX 轴行驶。此外还有两堵墙:一堵位于坐标 00,另一堵位于坐标 mm。

第 ii 个机器人起始于整数坐标 xi (0<xi<m)x_i~(0 \lt x_i \lt m),并以每秒 11 单位的速度向左(朝向 00)或向右运动。没有任何两个机器人起始位置相同。

每当一个机器人抵达一堵墙时,它会立即掉头,并以相同速度朝相反方向继续行驶。

当若干机器人在同一整数坐标相遇时,它们将发生碰撞并爆炸为尘埃。一旦某个机器人爆炸,它便不再与其他机器人发生碰撞。注意:若若干机器人在非整数坐标处相遇,则不会发生任何事件。

对每个机器人,请判断其是否会爆炸;若会爆炸,则输出其爆炸时刻;否则输出 −1-1。

输入格式

The first line contains a single integer tt (1≤t≤10001 \le t \le 1000) — the number of testcases.

Then the descriptions of tt testcases follow.

The first line of each testcase contains two integers nn and mm (1≤n≤3⋅1051 \le n \le 3 \cdot 10^5; 2≤m≤1082 \le m \le 10^8) — the number of robots and the coordinate of the right wall.

The second line of each testcase contains nn integers x1,x2,…,xnx_1, x_2, \dots, x_n (0<xi<m0 \lt x_i \lt m) — the starting coordinates of the robots.

The third line of each testcase contains nn space-separated characters 'L' or 'R' — the starting directions of the robots ('L' stands for left and 'R' stands for right).

All coordinates xix_i in the testcase are distinct.

The sum of nn over all testcases doesn't exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)——测试用例的数量。

接下来是 tt 个测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤3⋅1051 \le n \le 3 \cdot 10^5;2≤m≤1082 \le m \le 10^8)——机器人的数量和右墙的坐标。

每个测试用例的第二行包含 nn 个整数 x1,x2,…,xnx_1, x_2, \dots, x_n(0<xi<m0 \lt x_i \lt m)——机器人的初始坐标。

每个测试用例的第三行包含 nn 个由空格分隔的字符,每个字符为 'L' 或 'R' —— 机器人初始运动方向('L' 表示向左,'R' 表示向右)。

每个测试用例中所有坐标 xix_i 互不相同。

所有测试用例的 nn 值之和不超过 3⋅1053 \cdot 10^5。

输出格式

For each testcase print nn integers — for the ii-th robot output the time it explodes at if it does and −1-1 otherwise.

对于每个测试用例,输出 nn 个整数——对于第 ii 个机器人,若其会爆炸,则输出其爆炸的时间;否则输出 −1-1。

输入输出样例

  • 输入#1

    5
    7 12
    1 2 3 4 9 10 11
    R R L L R R R
    2 10
    1 6
    R R
    2 10
    1 3
    L L
    1 10
    5
    R
    7 8
    6 1 7 2 3 5 4
    R L R L L L L

    输出#1

    1 1 1 1 2 -1 2 
    -1 -1 
    2 2 
    -1 
    -1 2 7 3 2 7 3

说明/提示

Here is the picture for the seconds 0,1,20, 1, 2 and 33 of the first testcase:

Notice that robots 22 and 33 don't collide because they meet at the same point 2.52.5, which is not integer.

After second 33 robot 66 just drive infinitely because there's no robot to collide with.

第一个测试用例中第 00、11、22 和 33 秒的示意图如下:

注意:机器人 22 和 33 并未发生碰撞,因为它们在同一点 2.52.5 相遇,而该点不是整数。

第 33 秒之后,机器人 66 将无限行驶下去,因为其前方已无其他机器人可与其碰撞。

输入解题思路,AI测评打分。不知道怎么写?

首页