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. TSharding源码阅读

    需要的背景知识:Spring 和Mybatis 实现原理和源码, javaassist字节码增强的使用, java及设计模式的使用 1 读取解析数据库配置文件 DataSourceScanner实现了 ...

  2. Linux删除乱码文件的方法

    当文件名为乱码的时候,无法通过键盘输入文件名,所以在终端下就不能直接利用rm,mv等命令管理文件了. 我们可以通过以下几种方法删除linux下的乱码文件.(文件名为乱码) l  方法1 我们知道每个文 ...

  3. web 网页截取图片

    关于在UIwebview上添加滚动图片 两种滚动手势会混淆,应为webview有webview.scrollview的属性 故参照昨天的随笔 scrollview嵌套解决方案. 本篇随笔主要讲循环使用 ...

  4. IOS程序国际化

    1.1 新建一个Single View app模版项目,命名为Localization. 1.2 新建后,可以看到工作目录结构文件如下,单击InfoPlist.strings,查看右边的属性,在Loc ...

  5. IOS中UITableView异步加载图片的实现

    本文转载至 http://blog.csdn.net/enuola/article/details/8639404  最近做一个项目,需要用到UITableView异步加载图片的例子,看到网上有一个E ...

  6. Nearest Common Ancestors(LCA)

    Description A rooted tree is a well-known data structure in computer science and engineering. An exa ...

  7. centos出现-bash: /usr/bin/php: 没有那个文件或目录解决方法

    造成这个的原因是因为找不到php的执行文件导致的,原先我是安装的php5.4,然后卸载了重新安装php7,导致php可执行文件没有放到$PATH中,可以在终端测试:php -v,如果报错bash: / ...

  8. - symfony/icu v1.2.0 requires lib-icu >=4.4 -> the requested linked library icu has the wrong version installed or is missing from your system, ma

    $ composer install Loading composer repositories with package information Installing dependencies (i ...

  9. html post

    post请求对应的html页面 页面效果 html代码 <html> <body> <form method="post" > First na ...

  10. this.Hide()与this.Visible、Application.Exit与this.Close()区别

    首先明确this.Hide()和this.Visible作用完全一样,都是隐藏当前窗体,使其不可见:Application.Exit与this.Close()虽然都有关闭当前应用的作用,但作用不同. ...