首页 > 试题广场 >

Matrix

[编程题]Matrix
  • 热度指数:13 时间限制:C/C++ 4秒,其他语言8秒 空间限制:C/C++ 128M,其他语言256M
  • 算法知识视频讲解
Today HH is palying with a n×n matrix.
 All the numbers of the matrix is 0 initial, and every time HH will do one of the following things:
1.make all the numbers in the k row become v
2.make all the numbers in the k column become v
Now HH wants to know what's the final matrix after q options.     

输入描述:
The first line contains an positive integer T(1≤T≤10), represents there are T test cases. 
For each test case: 
The first line contains two positive integers n,q(1≤n≤500,1≤q≤2*105) - the size of the matrix and the times of the options. 
 Then q lines following, for each line contains three integers op,k,v(1≤op≤2,1≤k≤n,1≤v≤100). 
 if op=1, then HH will change all the numbers in the k row into v 
 if op=2, then HH will change all the numbers in the k column into v


输出描述:
For each test case, you should output n lines , each line n numbers , indicating the final matrix, note that for each line ,you should print exactly one blank between two numbers.
示例1

输入

1
3 3
1 2 3
2 2 1
1 1 3

输出

3 3 3
3 1 3
0 1 0

这道题你会答吗?花几分钟告诉大家答案吧!