6714.Nested Ranges Check

Time Limit: 2s Memory Limit: 512MB

Given $n$ ranges, your task is to determine for each range if it contains some other range and if some other range contains it.

Range $[a,b]$ contains range $[c,d]$ if $a \le c$ and $d \le b$ .

Input Format(From the terminal/stdin)

The first input line has an integer $n$ : the number of ranges.

After this, there are $n$ lines that describe the ranges. Each line has two integers $x$ and $y$ : the range is $[x,y]$ .

You may assume that no range appears more than once in the input.

  • $1 \le n \le 2 \cdot 10^5$
  • $1 \le x < y \le 10^9$

Output Format(To the terminal/stdout)

First print a line that describes for each range (in the input order) if it contains some other range (1) or not (0).

Then print a line that describes for each range (in the input order) if some other range contains it (1) or not (0).

Sample Input

Copy
4
1 6
2 4
4 8
3 6
 \n
 · \n
 · \n
 · \n
 · \n

Sample Output

Copy
1 0 0 0
0 1 0 1
 · · · \n
 · · · \n
Source: CSES, Sorting and Searching, 2168

Submit

请先 登录

© 2025 FAQs