#P15298. [ROI 2012 Day 2] mosaic 马赛克
[ROI 2012 Day 2] mosaic 马赛克
Background
Translation source: loj #5459. 「ROI 2012 Day 2」Mosaic.
Problem Description
All magnetic mosaic elements made by ABBYY are rectangles. Two elements can be connected only if they share at least one dimension (length, width, or both). Magnetic elements cannot be rotated or flipped. If two mosaic elements cannot be connected, they are called an inharmonious pair. For example, and form an inharmonious pair, while and , or and , are harmonious pairs.
ABBYY’s designers placed all mosaic elements in a single line, but did not connect them. We call a consecutive segment of elements in the line a set. They chose some sets to create an art installation, and need to determine whether each set contains an inharmonious pair of elements.
You need to write a program that, for each query segment of consecutive elements, finds the indices of two elements that form an inharmonious pair, or reports that no such pair exists in the segment.
Input Format
The first line of the input contains an integer , the number of mosaic elements.
The next lines each contain two integers and , representing the length and width of the -th mosaic element.
The -th line contains an integer , the number of sets to be checked for inharmonious pairs.
The next lines each contain two integers and , the indices of the first and last elements of a set, within which you need to find an inharmonious pair.
Output Format
The output should contain lines. Each line contains two integers separated by a space, the indices of two mosaic elements that form an inharmonious pair in the corresponding set. If multiple answers exist, you may output any one. If there is no inharmonious pair in the set, output 0 0.
4
2 2
1 2
1 3
2 3
2
2 3
2 4
0 0
4 2
Hint
Detailed additional constraints and scores for subtasks are shown in the table below.
| Subtask | Score | Additional Constraints |
|---|---|---|
| Number of mosaic elements , number of sets . | ||
| Number of mosaic elements , number of sets . | ||
| Number of mosaic elements , number of sets . | ||
| Number of mosaic elements , number of sets . |
Translated by ChatGPT 5