Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Sorting and Searching

Nested Ranges Check

#2168
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

Given nn 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][a,b] contains range [c,d][c,d] if a≤ca \le c and d≤bd \le b.

Input

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

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

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

Output

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).

Constraints
  • 1≤n≤2⋅1051 \le n \le 2 \cdot 10^5
  • 1≤x<y≤1091 \le x < y \le 10^9
Sample Test Cases (1)
Example 1ID: sample-1
Input
4
1 6
2 4
4 8
3 6
Expected Output
1 0 0 0
0 1 0 1
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
4
1 6
2 4
4 8
3 6
Expected Output
1 0 0 0
0 1 0 1