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. Sql Server 查询一段日期内的全部礼拜天

    /* 查询一段日期内的全部礼拜天 @startdate 開始日期 @enddate 结束日期 */ declare @startDate datetime declare @endDate datet ...

  2. Spring Cloud 微服务二:API网关spring cloud zuul

    前言:本章将继续上一章Spring Cloud微服务,本章主要内容是API 网关,相关代码将延续上一章,如需了解请参考:Spring Cloud 微服务一:Consul注册中心 Spring clou ...

  3. SQL Server研究之统计信息—发现过期统计信息并处理具体解释

     前言: 统计信息是关于谓词中的数据分布的主要信息源,假设不知道详细的数据分布,优化器不能获得预估的数据集.从而不能统计须要返回的数据. 在创建列的统计信息后,在DML操作如insert.upda ...

  4. Linux进程间通信(三) - 信号

    什么是信号 软中断信号(signal,又简称为信号)用来通知进程发生了异步事件.在软件层次上是对中断机制的一种模拟,在原理上,一个进程收到一个信号与处理器收到一个中断请求可以说是一样的.信号是进程间通 ...

  5. vue2 本地安装

  6. spring mvc 伪静态处理

    spring mvc 伪静态处理 @RequestMapping(value = JsonUrlCommand.webshare_get_opuss+"/u{u:[\\w\\W]+}p{p: ...

  7. First non repeating word in a file? File size can be 100GB.

    1 solution 1 1.1 数据结构 一个Hashmap和一个双向链表.如果想要快速获取first,并且只遍历一次,那么就要想到双向链表和HashMap的组合. 链表可以保证第一个在head处, ...

  8. Future Promise 模式(netty源码9)

    netty源码死磕9  Future Promise 模式详解 1. Future/Promise 模式 1.1. ChannelFuture的由来 由于Netty中的Handler 处理都是异步IO ...

  9. 我的Android进阶之旅------>关于android:layout_weight属性的一个面试题

    最近碰到一个面试题,按照下图,由Button和EditText组成的界面下厨布局代码,解决这题目需要使用android:layout_weight的知识. 首先分析上图所示的界面可以看成一下3个部分. ...

  10. windows下php升级到7.2

    1: 官网下载:https://windows.php.net/download#php-7.2