B. Print Check
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

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.

Your program has to support two operations:

  1. Paint all cells in row ri in color ai;
  2. Paint all cells in column ci in color ai.

If during some operation i there is a cell that have already been painted, the color of this cell also changes to ai.

Your program has to print the resulting table after k operation.

Input

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.

Each of the next k lines contains the description of exactly one query:

  • ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;
  • ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai.
Output

Print n lines containing m integers each — the resulting table after all operations are applied.

Examples
Input
3 3 3
1 1 3
2 2 1
1 2 2
Output
3 1 3 
2 2 2
0 1 0
Input
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
Output
1 1 1 
1 0 1
1 1 1
1 0 1
1 1 1
Note

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

题意: n*m的矩阵 两种操作 整行变换 与整列变换

ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai; 整行变为a

ci ai (1 ≤ ci ≤ m, 1 ≤ ai ≤ 109), means that column ci is painted in color ai. 整列变为a

输出k次变换后的矩阵;

题解:判断每一个位置上的数 其所在行的变换与所在列的变换的先后顺序以及变换结果  变换在后的 为结果  无变化的输出0;

 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
struct node
{
int sor;
int reu;
} a[],b[];
int n,m,k;
int q,w,e;
int main()
{
scanf("%d %d %d",&n,&m,&k);
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(int i=; i<=k; i++)
{
scanf("%d %d %d",&q,&w,&e);
if(q==)
{
a[w].sor=i;
a[w].reu=e;
}
else
{
b[w].sor=i;
b[w].reu=e;
}
}
for(int i=; i<=n; i++)
{
// cout<<a[i].sor<<" "<<b[i].sor<<endl;
if(a[i].sor>b[].sor)
printf("%d",a[i].reu);
else
{
if(a[i].sor<b[].sor)
printf("%d",b[].reu);
else
printf("");
} for(int j=; j<=m; j++)
{
if(a[i].sor>b[j].sor)
printf(" %d",a[i].reu);
else
{
if(a[i].sor<b[j].sor)
printf(" %d",b[j].reu);
else
printf("");
}
}
printf("\n");
}
return ;
}

Codeforces Round #344 (Div. 2) B的更多相关文章

  1. Codeforces Round #344 (Div. 2) A. Interview

    //http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...

  2. Codeforces Round #344 (Div. 2) A

    A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  3. Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳

    E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...

  4. Codeforces Round #344 (Div. 2) D. Messenger kmp

    D. Messenger 题目连接: http://www.codeforces.com/contest/631/problem/D Description Each employee of the ...

  5. Codeforces Round #344 (Div. 2) C. Report 其他

    C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ...

  6. Codeforces Round #344 (Div. 2) B. Print Check 水题

    B. Print Check 题目连接: http://www.codeforces.com/contest/631/problem/B Description Kris works in a lar ...

  7. Codeforces Round #344 (Div. 2) A. Interview 水题

    A. Interview 题目连接: http://www.codeforces.com/contest/631/problem/A Description Blake is a CEO of a l ...

  8. Codeforces Round #344 (Div. 2) B. Print Check

    B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. Codeforces Round #344 (Div. 2)(按位或运算)

    Blake is a CEO of a large company called "Blake Technologies". He loves his company very m ...

  10. Codeforces Round #344 (Div. 2)

    水 A - Interview 注意是或不是异或 #include <bits/stdc++.h> int a[1005], b[1005]; int main() { int n; sc ...

随机推荐

  1. beego 笔记

    1.开发文档 https://beego.me/docs/intro/ 2.bee run projectname demo controller package autoscaler import ...

  2. java length属性、length()、size()

    length属性 length是属性,用于说明数组的长度. String []list={"wo","shi","shuaibi"}; Sy ...

  3. 七:HDFS Permissions Guide 权限

    1.权限模式     简单:启动HDFS的操作系统用户即为超级用户,可以通过HADOOP_USER_NAME指定     kerberos: 2.group mapping      组列表由grou ...

  4. Graph Theory

    Description Little Q loves playing with different kinds of graphs very much. One day he thought abou ...

  5. ACM hust 2.1

    来自咸鱼王的呻吟 http://www.xiami.com/song/3599639?spm=a1z1s.3521865.23309997.1.PbLu7E 配合咸鱼食用效果更佳(右键新窗口打开) 题 ...

  6. lintcode-197-排列序号

    197-排列序号 给出一个不含重复数字的排列,求这些数字的所有排列按字典序排序后该排列的编号.其中,编号从1开始. 样例 例如,排列 [1,2,4] 是第 1 个排列. 思路 参考http://www ...

  7. MFC加速键

    添加的函数:    } // 解释说明    MFC对话框不自动处理加速键,你必须自己编写代码来做这件事情.为了理解弄清楚这是为什么,让我们回首Windows开发的历程,在使用C和原始的Windows ...

  8. Python的压缩文件处理 zipfile & tarfile

    本文从以下两个方面, 阐述Python的压缩文件处理方式: 一. zipfile 二. tarfile 一. zipfile 虽然叫zipfile,但是除了zip之外,rar,war,jar这些压缩( ...

  9. nginx 设置默认虚拟 host

    nginx 设置默认虚拟 host listren 80 default_server

  10. [计算机网络-应用层] HTTP协议

    1.HTTP概况 Web的应用层协议是超文本传输协议(HTTP),它是Web的核心. HTTP由两部分程序实现:一个客户机程序和一个服务器程序,它们运行在不同的端系统中,通过交换HTTP报文进行对话. ...