L. Visual Python++
event sponsor ICPC 2017 Problem L Visual Python++ Time limit: 5 seconds In the recently proposed Visual Python++ programming language, a block of statements is represented as a rectangle of characters with top-left corner in row r1 and column c1 , and botto...
Problem Statement
Formatted from the contest statement text, with sample tests broken out into copyable blocks.
In the recently proposed Visual Python++ programming language, a block of statements is represented as a rectangle of characters with top-left corner in row r1 and column c1 , and bottom-right corner in row r2 and column c2 . All characters at locations (r, c) with r1 ≤ r ≤ r2 and c1 ≤ c ≤ c2 are then considered to belong to that block. Among these locations, the ones with r = r1 or r = r2 or c = c1 or c = c2 are called a border. Statement blocks can be nested (rectangles contained in other rectangles) to an arbitrary level. In a syntac- tically correct program, every two statement blocks are either nested (one contained in the other) or disjoint (not overlapping). In both cases, their borders may not overlap. Programmers are not expected to draw the many rectangles contained in a typical program – this takes too long, and Visual Python++ would not have a chance to become the next ICPC programming language. So a programmer only has to put one character ‘p’ in the top-left corner of the rectangle and one character ‘y’ in the bottom-right corner. The parser will automatically match up the appropriate corners to obtain the nesting structure of the program. Your team has just been awarded a five-hour contract to develop this part of the parser.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 105 ), the number of corner pairs. Each of the next n lines contains two integers r and c (1 ≤ r, c ≤ 109 ), specifying that there is a top-left corner in row r and column c of the program you are parsing. Following that are n lines specifying the bottom-right corners in the same way. All corner locations are distinct.
Output
Display n lines, each containing one integer. A number j in line i means that the ith top-left corner and the j th bottom-right corner form one rectangle. Top-left and bottom-right corners are each numbered from 1 to n in the order they appear in the input. The output must be a permutation of the numbers from 1 to n such that the matching results in properly nested rectangles. If there is more than one valid matching, any one will be accepted. If no such matching exists, display syntax error.
Sample Tests
2
4 7
9 8
14 17
19 18 2
1
Rapid City
sponsor
ICPC 2017 2
4 7
14 17
9 8
19 18 1
2 2
4 8
9 7
14 18
19 17 syntax error 3
1 1
4 8
8 4
10 6
6 10
10 10 syntax error Editorial
The solution write-up is rendered from the LaTeX source, with equations kept live through MathJax.
Key Observations
Write the structural observations that make the problem tractable.
State any useful invariant, monotonicity property, graph interpretation, or combinatorial reformulation.
If the constraints matter, explain exactly which part of the solution they enable.
Algorithm
Describe the data structures and the state maintained by the algorithm.
Explain the processing order and why it is sufficient.
Mention corner cases explicitly if they affect the implementation.
Correctness Proof
We prove that the algorithm returns the correct answer.
Lemma 1.
State the first key claim.
Proof.
Provide a concise proof.
Lemma 2.
State the next claim if needed.
Proof.
Provide a concise proof.
Theorem.
The algorithm outputs the correct answer for every valid input.
Proof.
Combine the lemmas and finish the argument.
Complexity Analysis
State the running time and memory usage in terms of the input size.
Implementation Notes
Mention any non-obvious implementation detail that is easy to get wrong.
Mention numeric limits, indexing conventions, or tie-breaking rules if relevant.
Code
C++ solution used for this page.
#include <bits/stdc++.h>
using namespace std;
namespace {
void solve() {
// Fill in the full solution logic for the problem here.
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Source Files and Assets
Raw files are still available here when you want the original TeX, C++, or statement assets.
Show raw files
competitive_programming/icpc/2017/L-visual-python/solution.texC++ implementationcompetitive_programming/icpc/2017/L-visual-python/solution.cppStatement textcompetitive_programming/icpc/2017/L-visual-python/statement.txtStatement PDFcompetitive_programming/icpc/2017/L-visual-python/statement.pdfMetadatacompetitive_programming/icpc/2017/L-visual-python/meta.jsonYear packetcompetitive_programming/icpc/2017/contest_problems.pdf