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

题意:给你这些方格,然后让你涂颜色,问最后的状态是什么样的;

思路:后面涂的会覆盖前面涂的,所以从后往前确定,由于k>>n+m,所以很多都重复涂的,可以flag标记,涂过的就跳过,具体的见代码;

AC代码:

#include <bits/stdc++.h>
using namespace std;
int n,m,k;
const int N=5004;
int mp[N][N],flag1[N],flag2[N];
int a[100003],b[100003],c[100003];
int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=k;i++)
{
scanf("%d%d%d",&a[i],&b[i],&c[i]);
}
for(int i=k;i>0;i--)
{
if(a[i]==1)
{
if(!flag1[b[i]])
{
for(int j=1;j<=m;j++)
{
if(!mp[b[i]][j])mp[b[i]][j]=c[i];
}
flag1[b[i]]=1;
}
}
else
{
if(!flag2[b[i]])
{
for(int j=1;j<=n;j++)
{
if(!mp[j][b[i]]) mp[j][b[i]]=c[i];
}
flag2[b[i]]=1;
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<m;j++)
{
printf("%d ",mp[i][j]);
}
printf("%d\n",mp[i][m]);
}
return 0;
}

codeforces 631B B. Print Check的更多相关文章

  1. Codeforces 631B Print Check (思维)

    题目链接 Print Check 注意到行数加列数最大值只有几千,那么有效的操作数只有几千,那么把这些有效的操作求出来依次模拟就可以了. #include <bits/stdc++.h> ...

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

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

  4. Codeforces Round #344 (Div. 2) 631 B. Print Check (实现)

    B. Print Check time limit per test1 second memory limit per test256 megabytes inputstandard input ou ...

  5. 存储构造题(Print Check)

    连接:Print Check 题意:n行m列的矩阵,有k次涂色,每一涂一行或者一列,求最后的涂色结果. 从数据的大小看,暴力肯定要TLE: 问题是如何存储数据. 首先:我们只要最后的涂色结果. 其次: ...

  6. CodeForces 631B Print Check

    对于每一个格子,看是行最后画还是列最后画.预处理一下就可以了. #include<stdio.h> #include<string.h> int n,m,k; +]; +]; ...

  7. Codeforces 631B Print Check【模拟】

    题意: 按顺序给定列和行进行涂色,输出最终得到的方格颜色分布. 分析: 记录下涂的次序,如果某个元素的横和列都被涂过,那么就选择次序最大的颜色. 代码: #include<iostream> ...

  8. CodeForces 631C Print Check

    排序+构造+预处理 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm ...

  9. Codeforces - 631B 水题

    注意到R和C只与最后一个状态有关 /*H E A D*/ struct node2{ int kind,las,val,pos; node2(){} node2(int k,int l,int v,i ...

随机推荐

  1. Java之Filter

    一.何为Filter? Filter也称之为过滤器,它是Servlet技术中比較激动人心的技术.WEB开发者通过Filter技术.对webserver管理的全部web资源.换句话说其主要用于前台向后台 ...

  2. memcache 使用方法

    Memcache::add // 添加一个值,如果已经存在,则返回falseMemcache::addServer // 添加Memcache地址Memcache::close // 关闭一个Memc ...

  3. IOS发送带附件的邮件

    本文转载至  http://blog.csdn.net/zltianhen/article/details/7693810 1.加入邮箱的框架 #import <MessageUI/MFMail ...

  4. 经过两个多月的攻关,终于搞定了live555多线程并稳定压测通过

    live555已经发展了十几年了,不得不钦佩作者坚持不懈的奉献和国外的开源生态环境,live555可以说是大部分的安防从业者的入门之选,尤其是在嵌入式或者Linux系统上,其应用还是蛮广泛的,主要是其 ...

  5. css 坑记

    1. div 内容超出 (做换行处理)   要注意 white-space属性的运用 设置 div width:100%;(或者固定值) 设置换行  word-break: break-all; 设置 ...

  6. hibernate多对多关系配置

    一.创建用户,角色实体类. 一名用户可以有多个角色.一个角色可以对于多名用户. 用户实体类 public class User { private int uId; private String uN ...

  7. 路由器桥接(WIFI无线中继)设置及摆放位置图解

    路由器桥接(WIFI无线中继)设置及摆放位置图解 WIFI实在好用,但它的波覆盖面小.穿透力很差.我们安装时要考虑波的衍射特点,装在衍射效果最佳的位置(居中,室外可绕,避开密封墙).确实无法兼顾的地方 ...

  8. C#窗体互动

    说白了就是在一个窗体操作另外一个窗体的东西. 原理是把form2的数据提取出来,利用中间的静态类middle来传递数据,触发事件,调用委托,来修正form1 效果如下:   Form1.cs usin ...

  9. Ubuntu 16.04更换源

    Ubuntu 16.04下载软件速度有点慢,因为默认的是从国外下载软件,那就更换到国内比较好的快速更新源(就是这些软件所在的服务器),一般直接百度Ubuntu更新源就能出来一大堆,这时候最好是找和自己 ...

  10. [笔记]几个简单有用的PHP函数

    收藏几个简单的PHP函数,分别用于对象到数组转换.json到php数组转换功能.curl模拟POST以及根据链接获取内容.不直接使用json_decode()的原因是php json_decode() ...