Bellovin
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 858 Accepted Submission(s): 395
Peter would like to find another sequence b1,b2,...,bn in such a manner that F(a1,a2,...,an) equals to F(b1,b2,...,bn). Among all the possible sequences consisting of only positive integers, Peter wants the lexicographically smallest one.
The sequence a1,a2,...,an is lexicographically smaller than sequence b1,b2,...,bn, if there is such number i from 1 to n, that ak=bk for 1≤k<i and ai<bi.
The first contains an integer n (1≤n≤100000) -- the length of the sequence. The second line contains n integers a1,a2,...,an (1≤ai≤109).
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<cmath>
#define ll __int64
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int t;
int a[];
int ans[];
int n;
int main()
{
scanf("%d",&t);
{
for(int i=; i<=t; i++)
{
scanf("%d",&n);
scanf("%d",&a[]);
ans[]=;
int exm[];
int top=;
exm[]=a[];
for(int j=; j<n; j++)
{
scanf("%d",&a[j]); if(a[j]>exm[top])
{
top=top+;
exm[top]=a[j];
ans[j]=top;
}
else
{
int pos=lower_bound(exm,exm+top,a[j])-exm;
exm[pos]=a[j];
ans[j]=pos;
}
}
for(int j=; j<n; j++)
{
if(j==)
printf("%d",ans[j]);
else
printf(" %d",ans[j]);
}
printf("\n");
}
}
return ;
}