https://vjudge.net/contest/297216?tdsourcetag=s_pctim_aiomsg#problem/J
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
int b[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
memset(b,0,sizeof(b));
for(int i=1; i<=n; i++)
scanf("%d",&a[i]);
b[1]=a[1];
printf("1");
int len=1;
for(int i=2; i<=n; i++)
{
int p=lower_bound(b+1,b+1+len,a[i])-b;
printf(" %d",p);
if(a[i]>b[len])
b[++len]=a[i];
else
{
p=lower_bound(b+1,b+1+len,a[i])-b;
b[p]=a[i];
}
// for(int i=1;i<=len;i++)
// printf("%d ",b[i]);
}
printf("
");
}
}