B. Print Check

题目连接:

http://www.codeforces.com/contest/631/problem/B

Description

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:

Paint all cells in row ri in color ai;

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:

1 ri ai (1 ≤ ri ≤ n, 1 ≤ ai ≤ 109), means that row ri is painted in color ai;

2 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.

Sample Input

3 3 3

1 1 3

2 2 1

1 2 2

Sample Output

3 1 3

2 2 2

0 1 0

Hint

题意

给你一个n*m一开始全是0的矩阵,然后又q次询问

每次询问给你三个字母 op,a,b

将第a行变成b

将第a列变成b

然后让你输出Q次询问后,这个矩阵长什么模样

题解:

记录一下每一行每一列最后被变成了什么,以及时间戳

然后我们在判断这个格子最后是啥的时候,只用看他所在的这一行和这一列的时间戳哪个比较晚就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5005;
pair<int,int> r[maxn],c[maxn]; int main()
{
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++)
r[i]=make_pair(0,0);
for(int i=1;i<=m;i++)
c[i]=make_pair(0,0);
for(int i=1;i<=k;i++)
{
int x,y,z;scanf("%d%d%d",&x,&y,&z);
if(x==1)
r[y]=make_pair(z,i);
else
c[y]=make_pair(z,i);
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(r[i].first==0&&c[j].first==0)
printf("0 ");
else if(r[i].first==0)
printf("%d ",c[j].first);
else if(c[j].first==0)
printf("%d ",r[i].first);
else if(r[i].second>c[j].second)
printf("%d ",r[i].first);
else
printf("%d ",c[j].first);
}
printf("\n");
}
}

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

  1. 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 ...

  2. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  3. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  4. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  5. Codeforces Round #335 (Div. 2) B. Testing Robots 水题

    B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...

  6. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  7. Codeforces Round #353 (Div. 2) B. Restoring Painting 水题

    B. Restoring Painting 题目连接: http://www.codeforces.com/contest/675/problem/B Description Vasya works ...

  8. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

  9. Codeforces Round #335 (Div. 2) A. Magic Spheres 水题

    A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...

随机推荐

  1. bisai.py

    比赛专用py #!/usr/etc/env python #encoding:utf-8 #by i3ekr #token import re,os,requests res = "(fla ...

  2. Django【进阶】分页功能Pagination

    项目中,我们需要很多非业务逻辑的功能,例如分页功能,而且此类功能移植性很好,可以在不同的项目中使用,所以整理好这些功能会一定程度上提高开发效率,下面是分页功能代码,使用时,可单独放在utils目录 & ...

  3. spark 环境搭建坑

    spark的新人会有什么坑 spark是一个以java为基础的,以Scala实现的,所以在你在安装指定版本的spark,需要检查你用的是对应spark使用什么版本的scala,可以通过spark-sh ...

  4. how to create view (windows)

    View Server List  IP address: 200.xx.xx.xx How to create a new view ssh new view server by your Unix ...

  5. [New Learn]被嫌弃的app的一生

    1.简介 为什么叫被嫌弃的app的一生?致敬电影<被嫌弃的松子的一生>. 自学IOS东一锄西一镐的总感觉没有一个总的概念,还是多看看官网吧,先看一下一个app的整个生命周期,本文主要是翻译 ...

  6. vsftpd 虚拟用户配置

    vsftpd 虚拟用户的作用是 通过不同的虚拟用户可以有不同的根目录. 从 2.3.5 版本之后,vsftpd增强了安全检查,如果用户被限定在了其主目录下,则该用户的主目录不能在具有写权限了,如果检查 ...

  7. javascript方法--apply()

    今天琢磨了一下apply,以前对这个方法觉得比较懵,今天一琢磨确实觉得挺好玩的. 一开始把MDN的apply文档看了一遍,感觉不是很理解,而且有一些东西也是知道但是比较模糊,所以还是一步一步来,不懂查 ...

  8. 22:django 配置详解

    django配置文件包含了你的django安装的所有配置信息,本节为大家详细讲解django的配置 基本知识 一个配置文件只是一个包含模块级别变量的的python模块,所有的配置变量都是大写的,哈哈哈 ...

  9. HDU-5360

    Hiking Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Su ...

  10. jmeter+Jenkins 持续集成中发送邮件报错:MessagingException message: Exception reading response

    已经配置好了发送邮件的相关信息,但是执行完脚本出现报错:MessagingException message: Exception reading response 1.查看Jenkins本次构建的控 ...