#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
int n;
int a[maxn];
int tree[maxn<<2];
int res[maxn];
void build(int p,int l,int r){
tree[p]=0;
if(l==r){
scanf("%d",&a[l]);
return ;
}
int mid=(l+r)/2;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
}
void pushup(int p){
tree[p]=max(tree[p<<1],tree[p<<1|1]);
}
void update(int p,int l,int r,int pos,int val){
if(l==r){
tree[p]=val;
return ;
}
int mid=(l+r)/2;
if(pos<=mid) update(p<<1,l,mid,pos,val);
else update(p<<1|1,mid+1,r,pos,val);
pushup(p);
}
int query(int p,int l,int r,int L,int R){
if(L>R) return 0;
if(L<=l&&r<=R){
return tree[p];
}
int mid=(l+r)/2;
int res=0;
if(L<=mid) res=max(res,query(p<<1,l,mid,L,R));
if(R>mid) res=max(res,query(p<<1|1,mid+1,r,L,R));
return res;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
build(1,1,n);
int Max=0;
for(int i=1;i<=n;i++){
res[i]=query(1,1,n,a[i]+1,n)+1;
update(1,1,n,a[i],res[i]);
Max=max(Max,res[i]);
}
printf("%d\n",Max);
for(int i=1;i<=n;i++){
printf("%d ",res[i]);
}
printf("\n");
}
//system("pause");
return 0;
}
ICPC区域赛 昆明 Simone and graph coloring
最新推荐文章于 2022-04-23 16:38:56 发布