#BS0000175. Chọn điểm nguyên bằng vé trên các hình chữ nhật (Random Point in Non-overlapping Rectangles)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chọn điểm nguyên bằng vé trên các hình chữ nhật (Random Point in Non-overlapping Rectangles)
Random Point in Non-overlapping Rectangles — Ticket Mapping
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
You are given pairwise non-overlapping axis-aligned rectangles. Rectangle has bottom-left corner and top-right corner . Boundary points are included. Its number of integer lattice points is .
Number every lattice point starting at : visit rectangles in the input order; within each rectangle, visit rows by increasing , and visit points within each row by increasing . For each given ticket number , output the coordinates of the point bearing that ticket.
PHOJ Extended adaptation: The original LeetCode 497 API independently samples a lattice point uniformly at random. This version supplies tickets and checks their exact mapping to points. Uniform tickets generate a uniform distribution on all lattice points, but the contestant's random-number generator is not evaluated.
Input
The first line contains integers . Each of the following lines contains four integers . The last line contains ticket numbers .
Output
Print lines. Line contains two integers u v, the coordinates of the point owning ticket .
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; ; rectangles are pairwise non-overlapping; for every ticket.
- Subtask 2 (30 points): ; ; ; ; ; ; rectangles are pairwise non-overlapping; for every ticket.
- Subtask 3 (50 points): ; ; ; ; ; ; rectangles are pairwise non-overlapping; for every ticket.
Examples
Input
2 5
-2 -2 1 1
2 2 4 6
1 16 17 19 31
Output
-2 -2
1 1
2 2
4 2
4 6
Explanation
The first rectangle contains points, while the second contains points, making points in total. Ticket maps to ; ticket to ; ticket to ; ticket to the third point on the first row of the second rectangle, ; and ticket to .