codeforces631B
Print Check
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.
Examples
3 3 3
1 1 3
2 2 1
1 2 2
3 1 3
2 2 2
0 1 0
5 3 5
1 1 1
1 3 1
1 5 1
2 1 1
2 3 1
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.
sol:我们发现如果倒着做修改,每个点最多只会被修改一次,所以可以维护n个链表(每行一个),但是如果有许多列修改并且m=5000时就会被卡到5000*100000,所以对于列记一个bool数组表示是否被访问过,这样复杂度就对了
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=,B=;
int n,m,Q;
int Cor[N][N];
int Next[N][N];
bool Tag_Hang[N],Tag_Lie[N];
//n行,n个链表
struct Question
{
int opt,Pos,Cor;
}Que[B];
int main()
{
int i,j;
R(n); R(m); R(Q);
for(i=;i<=n;i++)
{
for(j=;j<=m;j++) Next[i][j]=j+;
}
for(i=;i<=Q;i++)
{
R(Que[i].opt); R(Que[i].Pos); R(Que[i].Cor);
}
for(i=Q;i>=;i--)
{
if(Que[i].opt==)
{
if(Tag_Hang[Que[i].Pos]) continue;
Tag_Hang[Que[i].Pos]=;
for(j=;j<=m;)
{
if(!Cor[Que[i].Pos][j])
{
Cor[Que[i].Pos][j]=Que[i].Cor;
Next[Que[i].Pos][j-]=Next[Que[i].Pos][j];
}
j=Next[Que[i].Pos][j];
}
}
else
{
if(Tag_Lie[Que[i].Pos]) continue;
Tag_Lie[Que[i].Pos]=;
for(j=;j<=n;j++)
{
if(!Cor[j][Que[i].Pos])
{
Cor[j][Que[i].Pos]=Que[i].Cor;
Next[j][Que[i].Pos-]=Next[j][Que[i].Pos];
}
}
}
}
for(i=;i<=n;i++,puts(""))
{
for(j=;j<=m;j++) W(Cor[i][j]);
}
return ;
}
/*
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
*/
codeforces631B的更多相关文章
随机推荐
- Vue2 第二天学习
个人小总结:1年多没有写博客,感觉很多知识点生疏了,虽然工作上能解决问题,但是当别人问到某个知识点的时候,还是迷迷糊糊的,所以坚持写博客是硬道理的,因为大脑不可能把所有的知识点记住,有可能某一天忘了, ...
- Android学习之基础知识十一 —运用手机多媒体
一.使用通知(Notification) 通知(Notification)是Android系统中比较有特色的一个功能,当某个应用程序希望向用户发出一些提示信息,而该应用程序又不在前台运行时,就可以借助 ...
- MySQL(六)常用语法和数据类型
阅读MySQL语法时,需要注意的规则: ①符号用来指出几个选择中的一个,比如:null | not null表示或者给出null或者给出not null: ②包含在方括号中的关键字或子句(如[like ...
- HDMI传输原理:TMDS
参考资料:http://blog.sina.com.cn/s/blog_679686370100vgg1.html: http://www.eeworld.com.cn/mndz/2011/0818/ ...
- Literal 字面值 字面量 的理解
Literal 字面值 字面量 Literal, 在程序语言中,指表示某种数据值的符码.如,123 是整数值符码, 3.14 是浮点值符码,abcd 是字串值符码,True, False, 是逻辑值符 ...
- VS诊断工具打开失败
使用管理员模式打开cmd,输入以下命令~ C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -iC:\Windows\Micros ...
- Intellij实用技巧
快捷键 Tradition 快捷键 介绍 Ctrl + Z 撤销 Ctrl + Shift + Z 取消撤销 Ctrl + X 剪切 Ctrl + C 复制 Ctrl + S 保存 Tab 缩进 Sh ...
- UVA10720 Graph Construction 度序列可图性
Luogu传送门(UVA常年上不去) 题意:求一个度序列是否可变换为一个简单图.$\text{序列长度} \leq 10000$ 题目看起来很简单,但是还是有一些小细节需要注意首先一个简单的结论:一张 ...
- Luogu1084 NOIP2012D2T3 疫情控制 二分答案、搜索、贪心、倍增
题目传送门 题意太长就不给了 发现答案具有单调性(额外的时间不会对答案造成影响),故考虑二分答案. 贪心地想,在二分了一个时间之后,军队尽量往上走更好.所以我们预处理倍增数组,在二分时间之后通过倍增看 ...
- Luogu P2002 消息扩散&&P1262 间谍网络
怕自己太久没写Tarjan了就会把这种神仙算法忘掉. 其实这种类型的图论题的套路还是比较简单且显然的. P2002 消息扩散 很显然的题目,因为在一个环(其实就是强连通分量)中的城市都只需要让其中一个 ...