Stamps are pressed onto a paper in a given order; later presses overwrite earlier ones. Print the final grid, using '.' for untouched cells.
Easy3SimulationArrayImplementationInterviewNo attempts yetTime limit4sMemory limit512 MBJunha is a painter who builds pictures out of stamps. He prepares several stamps of different sizes and shapes, then presses them onto a sheet of paper at chosen spots, one after another.
Gangmin wants to copy that method exactly. Given which stamp is pressed and where, in order, print the finished picture.
The paper starts out blank. Pressing a stamp turns every cell the stamp covers into the character at the matching spot of the stamp. A cell that already holds an earlier stamp is covered by the later one.
The first line contains the height N and the width M of the paper. (1≤N,M≤1000)
The second line contains the number of stamps K. (1≤K≤500) The stamps follow in order, numbered 1 through K. Each stamp starts with a line holding its height H and width W (1≤H,W≤500), followed by H lines of W characters each that give the shape of the stamp. Every cell of a stamp is an English letter or a digit, so a period never appears inside a stamp.
The next line contains the number of presses Q. (1≤Q≤10000) Each of the following Q lines contains a stamp number T and coordinates Y, X, given in the order the presses happen. (1≤T≤K, 0≤Y,X≤1000)
Y and X are the coordinates of the top left cell of the area the stamp covers. The top left cell of the paper is (0,0), Y counts down from the top and X counts right from the left. No press ever reaches outside the paper.
Print the finished paper on N lines. Each line holds M characters, and a cell that no stamp ever touched is printed as a period (.). The order of the presses must be visible in the result.