#P11115. Robot Service Statistics
Robot Service Statistics
Robot Service Statistics
You are given data about robots working on a planting area, each working exactly on a grid segment denoted by \( (x_1,x_2,y) \). For a given grid segment \( (x_1,x_2) \) in row \( y \), we say that the pair \( (x_1,x_2) \) is served on row \( y \) if there exists a robot working on that segment.
Your task is to:
- Identify all distinct pairs \( (x_1,x_2) \) that are served in at least one row.
- For each such pair, count the total number of rows in which it is served.
- For each pair, determine the maximum number of consecutive rows in which it is served. In other words, find the maximum integer \( k \) such that there exists a consecutive row interval \( [y_1,y_2] \) (with \( y_2-y_1+1=k \)) where the pair \( (x_1,x_2) \) is served in every row.
The input starts with an integer \( n \) representing the number of records. Each of the next \( n \) lines contains three integers \( x_1 \), \( x_2 \) and \( y \), indicating that a robot operates on grid segment \( (x_1,x_2,y) \). Multiple records may exist for the same pair and row, but they should be counted only once.
Output the results for each distinct pair \( (x_1,x_2) \) in ascending order (first by \( x_1 \) then by \( x_2 \)). For each pair, print four integers: \( x_1 \), \( x_2 \), the total number of distinct rows, and the maximum number of consecutive rows served.
Note: All formulas are formatted in \( \LaTeX \) format.
inputFormat
The first line of input contains a single integer \( n \) representing the number of service records. Each of the next \( n \) lines contains three space-separated integers \( x_1, x_2, y \) which indicate a robot working on grid segment \( (x_1,x_2,y) \).
outputFormat
For each unique pair \( (x_1,x_2) \) that appears in the input, output a line containing four space-separated integers: \( x_1 \), \( x_2 \), the total number of distinct rows in which the pair is served, and the maximum number of consecutive served rows. The output should be sorted in ascending order first by \( x_1 \) and then by \( x_2 \).
sample
4
1 3 2
1 3 3
2 4 5
1 3 5
1 3 3 2
2 4 1 1
</p>