codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

631B.md (2366B)


      1 Source: https://codeforces.com/problemset/problem/631/B
      2 
      3 B. Print Check
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the printing.
     22 
     23 Printer works with a rectangular sheet of paper of size *n* × *m*. Consider the list as a table consisting of *n* rows and *m* columns. Rows are numbered from top to bottom with integers from 1 to *n*, while columns are numbered from left to right with integers from 1 to *m*. Initially, all cells are painted in color 0.
     24 
     25 Your program has to support two operations:
     26 
     27 1. Paint all cells in row *r**i* in color *a**i*;
     28 2. Paint all cells in column *c**i* in color *a**i*.
     29 
     30 If during some operation *i* there is a cell that have already been painted, the color of this cell also changes to *a**i*.
     31 
     32 Your program has to print the resulting table after *k* operation.
     33 
     34 Input
     35 
     36 The first line of the input contains three integers *n*, *m* and *k* (1  ≤  *n*,  *m*  ≤ 5000, *n*·*m* ≤ 100 000, 1 ≤ *k* ≤ 100 000) — the dimensions of the sheet and the number of operations, respectively.
     37 
     38 Each of the next *k* lines contains the description of exactly one query:
     39 
     40 * 1 *r**i* *a**i* (1 ≤ *r**i* ≤ *n*, 1 ≤ *a**i* ≤ 109), means that row *r**i* is painted in color *a**i*;
     41 * 2 *c**i* *a**i* (1 ≤ *c**i* ≤ *m*, 1 ≤ *a**i* ≤ 109), means that column *c**i* is painted in color *a**i*.
     42 
     43 Output
     44 
     45 Print *n* lines containing *m* integers each — the resulting table after all operations are applied.
     46 
     47 Examples
     48 
     49 Input
     50 
     51 ```
     52 3 3 3  
     53 1 1 3  
     54 2 2 1  
     55 1 2 2
     56 ```
     57 
     58 Output
     59 
     60 ```
     61 3 1 3   
     62 2 2 2   
     63 0 1 0
     64 ```
     65 
     66 Input
     67 
     68 ```
     69 5 3 5  
     70 1 1 1  
     71 1 3 1  
     72 1 5 1  
     73 2 1 1  
     74 2 3 1
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 1 1 1   
     81 1 0 1   
     82 1 1 1   
     83 1 0 1   
     84 1 1 1
     85 ```
     86 
     87 Note
     88 
     89 The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray.
     90 
     91  ![](https://espresso.codeforces.com/d04457c0764ca27b1fb20bc9b32938656b0c0fd4.png)