Codeforces Round #344 (Div. 2) B. Print Check 水题
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 水题的更多相关文章
- 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 ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- 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 ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- 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 ...
- 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 ...
- Codeforces Round #353 (Div. 2) B. Restoring Painting 水题
B. Restoring Painting 题目连接: http://www.codeforces.com/contest/675/problem/B Description Vasya works ...
- Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...
- 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/ ...
随机推荐
- python中requests库中文乱码问题
当使用这个库的时候经常会出现各种乱码的情况. 首先要知道: text返回的是处理过的unicode的数据. content返回的是bytes的原始数据 也就是说r.content比r.text更加节省 ...
- linux编程之文件操作
在linux下用文件描述符来表示设备文件盒普通文件,文件描述符是一个整型的数据,所有对文件的操作都是通过文件描述符来实现的. 文件描述符是文件系统中连接用户空间和内核空间的枢纽,当我们打开一个或者创建 ...
- 【LA3882】And then there was one
做sb题也是一种乐趣,是吧…… #include<bits/stdc++.h> #define N 10005 using namespace std; int f[N],m,n,k; i ...
- .net设置浏览器的文本模式
这段时间做个项目,做的时候因为之前习惯了Google的调试方式,所以就一直在google上面调试,今天项目成员大家的部分要整合,就放到ie8下面测试,但是遇到一个问题,就是用ie打开之后文本模式一直是 ...
- IDEA 内存设置
-server -Xms2g -Xmx2g -XX:NewRatio=3 -Xss16m -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled - ...
- shell常见操作整理(更新)
查看文件第20到30行的内容 法一:[root@oldboy ~]# seq 100 > ett.txt [root@oldboy ~]# head -30 ett.txt | tail -11 ...
- 03 java 基础:注释 关键字 标识符 JShell
Java 10 中已有 Jshell 工具,方便用户在其中直接输入相关 java 代码. 注释:java 中分为单行注释 // 多行注释 /* */ 文档注释 /** */ 关键字:在 ...
- CentOS 6.7下配置 yum 安装 Nginx
CentOS 6.7下配置 yum 安装 Nginx. 转载:http://www.linuxidc.com/Linux/2016-07/133283.htm 第一步,在/etc/yum.repos. ...
- 【剑指offer】面试题 2. 实现 Singleton 模式
面试题 2. 实现 Singleton 模式 题目:设计一个类,我们只能生成该类的一个实例. 单例模式:确保一个类只有一个实例,并提供了一个全局访问点. Java 实现 1.饿汉模式 //饿汉模式 p ...
- centos 新增用户, 然后他在主目录添加网站403Forbbiden
是 /home/zhou 这个文件夹的权限不够 往往看了网站目录并且给了777权限了,还是403,就是因为父目录的权限不够