B. Print Check

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard 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:

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

inputCopy

3 3 3

1 1 3

2 2 1

1 2 2

outputCopy

3 1 3

2 2 2

0 1 0

inputCopy

5 3 5

1 1 1

1 3 1

1 5 1

2 1 1

2 3 1

outputCopy

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.

B. Print Check

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard 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:

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

inputCopy

3 3 3

1 1 3

2 2 1

1 2 2

outputCopy

3 1 3

2 2 2

0 1 0

inputCopy

5 3 5

1 1 1

1 3 1

1 5 1

2 1 1

2 3 1

outputCopy

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.

题意:

给你一个初始为0的n*m数组,和k个操作,每一个操作把一行或者一列变为指定的数字。让你输出最后的结果

思路:

用两个pair<int,int> 数组 r和l来记录当前行或列在第几次操作被更新,以及被更新的值是多少。

输出答案的时候记录行和列的时间戳哪个比较靠后更新就输出谁,没有记录就是0.

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {ll ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
inline void getInt(int* p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int a[5003][5003];
int n,m,k;
pii r[maxn];
pii c[maxn];
int main()
{
//freopen("D:\\code\\text\\input.txt","r",stdin);
//freopen("D:\\code\\text\\output.txt","w",stdout);
gbtb;
cin>>n>>m>>k;
int op,x,y;
repd(i,1,k)
{
cin>>op>>x>>y;
if(op==1)
{
r[x].fi=y;
r[x].se=i;
}else
{
c[x].fi=y;
c[x].se=i;
}
}
repd(i,1,n)
{
repd(j,1,m)
{
if(r[i].se>c[j].se)
{
cout<<r[i].fi<<" ";
}else if(r[i].se<c[j].se)
{
cout<<c[j].fi<<" ";
}else
{
cout<<0<<" ";
}
}
cout<<endl;
}
return 0; } inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 - ch + '0';
}
}
else {
*p = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') {
*p = *p * 10 + ch - '0';
}
}
}

Codeforces Round #344 (Div. 2) 631 B. Print Check (实现)的更多相关文章

  1. Codeforces Round #344 (Div. 2) 631 C. Report (单调栈)

    C. Report time limit per test2 seconds memory limit per test256 megabytes inputstandard input output ...

  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)

    水 A - Interview 注意是或不是异或 #include <bits/stdc++.h> int a[1005], b[1005]; int main() { int n; sc ...

  5. Codeforces Round #344 (Div. 2) B

    B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳

    E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...

  7. Codeforces Round #344 (Div. 2) D. Messenger kmp

    D. Messenger 题目连接: http://www.codeforces.com/contest/631/problem/D Description Each employee of the ...

  8. Codeforces Round #344 (Div. 2) C. Report 其他

    C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ...

  9. Codeforces Round #344 (Div. 2) A. Interview 水题

    A. Interview 题目连接: http://www.codeforces.com/contest/631/problem/A Description Blake is a CEO of a l ...

随机推荐

  1. 从Windows系统到Linux系统转变的5大要点

    当我在 Algoma  (阿尔格玛)大学开始我现在的工作,一个图书系统管理员,我实在是对我的工作没有什么信心.尽管我在图书信息技术上有十年经验,对于我的第一个任务——协助开发和管理 Evergreen ...

  2. SQL Server 2005 和自增长主键identity说再见——NEWSEQUENTIALID()(转载)

    在SQL Server 2005环境下,表的主键应该怎样设计.目前主要用到的主键方案共三种: 自动增长主键 手动增长主键 UNIQUEIDENTIFIER主键 1.先说自动增长主键,它的优点是简单,类 ...

  3. Number 和 Math 类

    Java Number & Math 类 一般地,当需要使用数字的时候,我们通常使用内置数据类型,如:byte.int.long.double 等. 然而,在实际开发过程中,我们经常会遇到需要 ...

  4. JobHandle和依赖项

    要当您调用作业的Schedule方法时,它将返回JobHandle.您可以在代码中使用一个JobHandle作为其他作业的依赖项.如果作业取决于另一个作业的结果,您可以将第一个作业JobHandle作 ...

  5. DataGridView中的ComboboxCell报了System.ArgumentException:DagaGridViewComboBoxCell值无效错误

    原因是初始化的时候给ComboboxCell绑定了一系列的值,但是真正赋值的时候却给了一个不在那一系列值范围中的值,所以就报了这个错 在开发的时候难免会因为数据的问题出现这个问题,为了不让系统崩掉,就 ...

  6. 菜鸟系列k8s——k8s集群部署(2)

    k8s集群部署 1. 角色分配 角色 IP 安装组件 k8s-master 10.0.0.170 kube-apiserver,kube-controller-manager,kube-schedul ...

  7. HDU 1203 I NEED A OFFER! (动态规划、01背包、概率)

    I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. vue组件添加事件@click.native

    1,给vue组件绑定事件时候,必须加上native ,否则会认为监听的是来自Item组件自定义的事件 2,等同于在子组件中:  子组件内部处理click事件然后向外发送click事件:$emit(&q ...

  9. GDOI2018游记

    前言 不知怎的,本蒟蒻居然拿到了GDOI参赛名额 于是乎,我稀里糊涂地跟着诸位大佬屁颠屁颠地来到了阔别已久的中山一中 腐败difficult and interesting的GDOI比赛就这样开始了. ...

  10. 小白学习tornado第二站-tornado简单介绍

    tornado基本web应用结构 分为两大块类 Application对象(只会实例化一次) 路由表URl映射 (r'/', MainHandler) 关键词参数settings RequestHan ...