codeforces-scrape

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

320B.md (1581B)


      1 Source: https://codeforces.com/problemset/problem/320/B
      2 
      3 B. Ping-Pong (Easy Version)
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 In this problem at each moment you have a set of intervals. You can move from interval (*a*, *b*) from our set to interval (*c*, *d*) from our set if and only if *c* < *a* < *d* or *c* < *b* < *d*. Also there is a path from interval *I*1 from our set to interval *I*2 from our set if there is a sequence of successive moves starting from *I*1 so that we can reach *I*2.
     22 
     23 Your program should handle the queries of the following two types:
     24 
     25 1. "1 x y" (*x* < *y*) — add the new interval (*x*, *y*) to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals.
     26 2. "2 a b" (*a* ≠ *b*) — answer the question: is there a path from *a*-th (one-based) added interval to *b*-th (one-based) added interval?
     27 
     28 Answer all the queries. Note, that initially you have an empty set of intervals.
     29 
     30 Input
     31 
     32 The first line of the input contains integer *n* denoting the number of queries, (1 ≤ *n* ≤ 100). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value.
     33 
     34 It's guaranteed that all queries are correct.
     35 
     36 Output
     37 
     38 For each query of the second type print "YES" or "NO" on a separate line depending on the answer.
     39 
     40 Examples
     41 
     42 Input
     43 
     44 ```
     45 5  
     46 1 1 5  
     47 1 5 11  
     48 2 1 2  
     49 1 2 9  
     50 2 1 2
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 NO  
     57 YES
     58 ```