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. Python全栈 Web(概述、HTML基础语法)

    原文地址: https://yq.aliyun.com/articles/631222 ........................................................ ...

  2. vector的基础使用

    vector是一个容器,实现动态数组. 相似点:下标从0开始. 不同点:vector创建对象后,容器大小会随着元素的增多或减少而变化. 基础操作: 1.使用vector需要添加头文件,#include ...

  3. 数据库Mysql的学习(三)-各种约束

    删除数据库表 drop table [if exists] 表一,表二.....; 表分区:比如图书信息表有1000万个图书信息,如何优化他,其中一种方式就是表分区.就是把一张表的数据分成多个区块,这 ...

  4. centos 6.5 启动时卡在进度条位置无法进入系统解决办法。

    今天公司服务器因突然断电导致phddns 花生壳 启动失败,一直卡在启动进度条页面. 解决办法 1.按F5查看卡在什么位置, 2.查看解决方法:程序卡住的情况下,直接备份资料后,卸载程序重启就可以了. ...

  5. Python对文本文件逐行扫描,将含有关键字的行存放到另一文件

    #逐行统计关键字行数,并将关键字所在行存放在新的文件中 keyword = "INFO" b = open("C:\\Users\\xxx\\Documents\\new ...

  6. Ubuntu—终端下重启与关机

    重启命令 :         1.shutdown -r now 立刻重启    2.shutdown -r 10 过10分钟自动重启    3.shutdown -r 20:35 在时间为20:35 ...

  7. hive创建外部表

    Create [EXTERNAL] TABLE [IF NOT EXISTS] table_name [(col_name data_type [COMMENT col_comment], ...)] ...

  8. VBA基础之Excel VBA 表格的操作(一)

    一.Excel VBA 表格的操作1. Excel表格的指定以及表格属性的设置 Sub main() '把表格B2的值改为"VBA Range和Cells函数" Range(&qu ...

  9. 软工实践Alpha冲刺(2/10)

    队名:我头发呢队 组长博客 作业博客 杰(组长) 过去两天完成了哪些任务 查看了讯飞开放平台的sdk 查阅了Google Material Design 2的官方文档 接下来的计划 继续打磨UI界面: ...

  10. lintcode-189-丢失的第一个正整数

    189-丢失的第一个正整数 给出一个无序的正数数组,找出其中没有出现的最小正整数. 样例 如果给出 [1,2,0], return 3 如果给出 [3,4,-1,1], return 2 挑战 只允许 ...