CF342B.Xenia and Spies
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right.
Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the note to one of his neighbours in the row. In other words, if this spy's number is x, he can pass the note to another spy, either x - 1 or x + 1 (if x = 1 or x = n, then the spy has only one neighbour). Also during a step the spy can keep a note and not pass it to anyone.
But nothing is that easy. During m steps Xenia watches some spies attentively. Specifically, during step t__i (steps are numbered from 1) Xenia watches spies numbers l__i, l__i + 1, l__i + 2, ..., r__i (1 ≤ l__i ≤ r__i ≤ n). Of course, if during some step a spy is watched, he can't do anything: neither give the note nor take it from some other spy. Otherwise, Xenia reveals the spies' cunning plot. Nevertheless, if the spy at the current step keeps the note, Xenia sees nothing suspicious even if she watches him.
You've got s and f. Also, you have the steps during which Xenia watches spies and which spies she is going to watch during each step. Find the best way the spies should act in order to pass the note from spy s to spy f as quickly as possible (in the minimum number of steps).
充满活力的侦探克谢尼娅面对排成一排的 n(n≥2)名外国间谍。我们将从左到右将这些间谍编号为 1 到 n。
间谍 s 持有一份重要笔记,他必须将该笔记传递给间谍 f。克谢尼娅将分若干步对间谍进行审讯。在每一步中,当前持有重要笔记的间谍可将其传递给其在队列中的某一位相邻间谍。换言之,若该间谍编号为 x,则他可将笔记传给编号为 x−1 或 x+1 的间谍(若 x=1 或 x=n,则该间谍仅有一个邻居)。此外,在某一步中,持有笔记的间谍也可选择不传递笔记,即原地保留。
但事情并非如此简单。在总共 m 步中,克谢尼娅会特别严密监视某些间谍。具体而言,在第 ti 步(步骤从 1 开始编号),她会监视编号范围为 li,li+1,li+2,…,ri 的间谍(其中 1≤li≤ri≤n)。显然,若在某一步中某间谍正被监视,则他不能执行任何动作:既不能传递笔记,也不能从其他间谍处接收笔记;否则克谢尼娅便会识破间谍们狡猾的阴谋。然而,若某间谍在当前步骤中正持有笔记(即未传递也未接收),即使克谢尼娅正在监视他,她也不会察觉任何异常。
已知初始持笔记者编号 s 和目标接收者编号 f,同时已知克谢尼娅监视间谍的 m 个步骤及其每步所监视的间谍区间。请找出间谍们应采取的最优策略,使得笔记能从间谍 s 尽快(即最少步数)传递至间谍 f。
输入格式
The first line contains four integers n, m, s and f (1 ≤ n, m ≤ 105; 1 ≤ s, f ≤ n; s ≠ f; n ≥ 2). Each of the following m lines contains three integers t__i, l__i, r__i (1 ≤ t__i ≤ 109, 1 ≤ l__i ≤ r__i ≤ n). It is guaranteed that _t_1 < _t_2 < _t_3 < ... < t__m.
第一行包含四个整数 n、m、s 和 f(1 ≤ n, m ≤ 105;1 ≤ s, f ≤ n;s = f;n ≥ 2)。接下来的 m 行中,每行包含三个整数 ti、li、ri(1 ≤ ti ≤ 109,1 ≤ li ≤ ri ≤ n)。保证 t1 < t2 < t3 < … < tm。
输出格式
Print k characters in a line: the i-th character in the line must represent the spies' actions on step i. If on step i the spy with the note must pass the note to the spy with a lesser number, the i-th character should equal "L". If on step i the spy with the note must pass it to the spy with a larger number, the i-th character must equal "R". If the spy must keep the note at the i-th step, the i-th character must equal "X".
As a result of applying the printed sequence of actions spy s must pass the note to spy f. The number of printed characters k must be as small as possible. Xenia must not catch the spies passing the note.
If there are miltiple optimal solutions, you can print any of them. It is guaranteed that the answer exists.
每行输出 k 个字符:第 i 个字符表示间谍在第 i 步的动作。若在第 i 步,持有纸条的间谍需将纸条传递给编号更小的间谍,则第 i 个字符应为 "L";若需传递给编号更大的间谍,则第 i 个字符应为 "R";若在第 i 步该间谍需保留纸条,则第 i 个字符应为 "X"。
执行所输出的动作序列后,间谍 s 必须将纸条传递给间谍 f。输出的字符数 k 应尽可能小。Xenia 不得发现间谍传递纸条的行为。
若存在多个最优解,可输出其中任意一个。题目保证答案存在。
输入输出样例
输入#1
3 5 1 3 1 1 2 2 2 3 3 3 3 4 1 1 10 1 3
输出#1
XXRR
输入解题思路,AI测评打分。不知道怎么写?