Under construction

Still being built. Things may change

Go 2

Time limit3sMemory limit1024 MB

Summary
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 NN, the number of matches placed. The next NN lines each contain two numbers xix_i and yiy_i and a character cic_i, separated by spaces. Each corner is identified by its coordinates xx and yy. If cc is x, the match is placed on the edge between (x,y)(x, y) and (x+1,y)(x + 1, y). If cc is y, the match is placed on the edge between (x,y)(x, y) and (x,y+1)(x, y + 1).

Output

Output NN lines. The ii-th line contains a single number sis_i, the number of points the ii-th match is worth.

Limits

  • 1≤N≤3⋅1051 \le N \le 3 \cdot 10^5
  • 0≤xi,yi≤1080 \le x_i, y_i \le 10^8 for each ii such that 1≤i≤N1 \le i \le N
  • 0≤si≤1080 \le s_i \le 10^8 for each ii such that 1≤i≤N1 \le i \le N

Examples1

  1. Example 1

    Input
    4
    0 0 x
    0 0 y
    1 0 y
    0 1 x
    
    Expected output
    0
    0
    0
    1