Go 2
Time limit3sMemory limit1024 MB
Matches are placed one at a time on grid edges; for each, output the area it encloses (0 if none), and enclosing matches are removed.
- Level
Hard8 of 10
- Topics
- Union-find, Graph, Implementation
- Solved
- No attempts yet
Problem
On the evening before the first day of CEOI 2024, Křemílek and Vochomůrka sit in their room, nervous about what comes next. To pass the time, they decide to play a game of Go. They have no Go board. Luckily, Křemílek always carries a matchbox in his pocket, and Vochomůrka has an infinite grid in his backpack, so they can play Go 2.
Go 2 differs from Go in two ways: the board and the rules.
Go 2 is played on a square grid. Players take turns placing matches on the grid. A match may be placed on any edge between two squares. If placing a match creates an enclosed area, the player who placed it receives points equal to the area of the enclosed space, and the match is removed. Otherwise, the player receives no points and the match stays on the grid. A match may not be placed at a position where a match was placed before, even if that match has since been removed.
Input
The first line contains the integer , the number of matches placed. The next lines each contain two numbers and and a character , separated by spaces. Each corner is identified by its coordinates and . If is x, the match is placed on the edge between and . If is y, the match is placed on the edge between and .
Output
Output lines. The -th line contains a single number , the number of points the -th match is worth.
Limits
- for each such that
- for each such that