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:
- make all the numbers in the k row become v
- 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≤1000) -
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
#include <iostream>
#include <cstdio>
#include <cstring>
using namespacestd;
const int maxn =505;
int h[maxn][2],l[maxn][2];
int main()
{
int T;
scanf("%d",&T);
while (T --) {
int n,q;
scanf("%d%d",&n,&q);
memset(h,0,sizeof(h));
memset(l,0,sizeof(l));
int op,k,v;
for (int i =1; i <= q; i ++) {
scanf("%d%d%d",&op,&k,&v);
if(op ==1)
{
h[k][0] = v;
h[k][1] = i;
}
elseif(op ==2){
l[k][0] = v;
l[k][1] = i;
}
}
for (int i =1; i <= n; i ++) {
for (int j =1; j <= n; j ++) {
if (j !=1) {
printf(" ");
}
if (h[i][1] >l[j][1]) {
printf("%d",h[i][0]);
}
elseif(h[i][1] <l[j][1])
{
printf("%d",l[j][0]);
}
elseprintf("0");
}
printf("\n");
}
}
return0;
}