#BS0000153. Tìm đoạn ở bên phải (Find Right Interval)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tìm đoạn ở bên phải (Find Right Interval)
Find Right Interval
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are closed intervals numbered from to in input order. All starting points are distinct.
A right interval for interval is an interval with and the smallest possible . If no such interval exists, return . The right interval may be interval itself. Print the corresponding original indices in input order.
Input
- The first line contains the number of intervals.
- Each of the next lines contains the start and end for zero-based index .
Output
Print integers in one line. The -th answer is the zero-based index of the right interval for interval , or if none exists.
Subtasks
- Subtask 1 (20 points): ; ; all are distinct.
- Subtask 2 (30 points): ; ; all are distinct.
- Subtask 3 (50 points): ; ; all are distinct.
Examples
Example 1
Input
3
3 4
2 3
1 2
Output
-1 0 1
Explanation
The intervals are , , and . No start is at least , so interval yields . For interval , start of interval matches its end, so the answer is . For interval , eligible starts are and ; the smaller belongs to interval , so the answer is .