#P6265. [COCI 2014/2015 #3] SILUETA

[COCI 2014/2015 #3] SILUETA

Background

One day, the painter Vincent found himself in a big city full of skyscrapers, so he immediately sat down to paint, enjoying this wonderful view. For some reasons that ordinary programmers cannot understand, Vincent decided to draw only the outline of the skyscrapers in front of him. Unfortunately, one week after he finished this masterpiece, the painting was burned.

To rebuild the painting, Vincent has asked for help in all directions, and now it is your turn.

Problem Description

From your point of view, Vincent’s skyscrapers are rectangles whose sides are parallel to the coordinate axes, with one side lying on the xx-axis. In the picture, the xx-axis should be drawn using the character *, the outline of the skyscrapers using #, and everything else using .. The left edge of the picture must start with a skyscraper, and the right edge of the picture must end with a skyscraper. Also, to verify the result obtained by mathematicians, output the perimeter of the given outline, instead of counting the side that lies on the xx-axis.

Input Format

The first line contains an integer nn, the number of skyscrapers.

Each of the next nn lines contains three integers li,ril_i, r_i and hih_i, describing the position of the ii-th skyscraper. In the Cartesian coordinate system, the skyscraper is treated as a rectangle with the bottom-left corner at (li,0)(l_i, 0) and the top-right corner at (ri,hi)(r_i, h_i).

Output Format

Output an integer on the first line, the perimeter of the skyscraper outline.

In the next h+1h + 1 lines, where h+1h + 1 is the height of the tallest skyscraper, output Vincent’s drawing as described above.

3
1 5 4
7 11 3
9 13 5

28
........####
####....#..#
#..#..###..#
#..#..#....#
#..#..#....#
************

6
2 8 7
5 13 5
2 18 3
23 26 5
20 31 7
21 30 10
61
...................#########.
...................#.......#.
...................#.......#.
######............##.......##
#....#............#.........#
#....######.......#.........#
#.........#.......#.........#
#.........######..#.........#
#..............#..#.........#
#..............#..#.........#
*****************************

Hint

Explanation of Sample Input/Output 1

In the figure below, blue shows the skyscraper outline (character #), and yellow is the part of the xx-axis in Vincent’s painting (character *).

Constraints

  • For 50%50\% of the testdata, 1n1001 \le n \le 100, and 1li,ri,hi1001 \le l_i, r_i, h_i \le 100.
  • For 100%100\% of the testdata, 1n1041 \le n \le 10^4, 1li,ri,hi1031 \le l_i, r_i, h_i \le 10^3, and 3rili1033 \leq r_i - l_i \leq 10^3.

Translated by ChatGPT 5