1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include<iostream>
#include<cstdio>
using namespace std;
#define inf 100000
struct array
{
int x;
int y;
};
void merge(struct array [],int,int,int);
void mergesort(struct array a[],int low,int high)
{
if(low<high)
{
int mid=(low+high)/2;
mergesort(a,low,mid);
mergesort(a,mid+1,high);
merge(a,low,mid,high);
}
}
void merge(struct array a[],int low,int mid,int high)
{
int n1,n2,i,j,k;
n1=mid-low+1;
n2=high-mid;
int l[n1+1],r[n2+1],p[n1+1],q[n2+1];
for(i=1;i<=n1;i++)
{
l[i]=a[low+i-1].x;
p[i]=a[low+i-1].y;
}
for(j=1;j<=n2;j++)
{
r[j]=a[mid+j].x;
q[j]=a[mid+j].y;
}
l[i+1]=inf;
r[j+1]=inf;
p[i+1]=inf;
q[j+1]=inf;
i=1;
j=1;
for(k=low;k<=high;k++)
{
if(l[i]<=r[j])
{
a[k].x=l[i];
a[k].y=p[i];
i++;
}
else
{
a[k].x=r[j];
a[k].y=q[j];
j++;
}
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int i;
struct array b[n+1],c[n+1];
for(i=1;i<=n;i++)
{
scanf("%d",&b[i].x);
}
for(i=1;i<=n;i++)
{
scanf("%d",&c[i].x);
}
for(i=1;i<=n;i++)
{
b[i].y=i;
c[i].y=i;
}
mergesort(b,1,n);
for(i=1;i<=n;i++)
{
printf("%d ",b[i].x);
}
mergesort(c,1,n);
printf("\n");
for(i=1;i<=n;i++)
{
printf("%d ",c[i].x);
}
}
return 0;
}
|