codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

342B.md (2949B)


      1 Source: https://codeforces.com/problemset/problem/342/B
      2 
      3 B. Xenia and Spies
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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.
     22 
     23 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.
     24 
     25 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.
     26 
     27 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).
     28 
     29 Input
     30 
     31 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*.
     32 
     33 Output
     34 
     35 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".
     36 
     37 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.
     38 
     39 If there are miltiple optimal solutions, you can print any of them. It is guaranteed that the answer exists.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 3 5 1 3  
     47 1 1 2  
     48 2 2 3  
     49 3 3 3  
     50 4 1 1  
     51 10 1 3
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 XXRR
     58 ```