package 第10周_蓝桥杯;
import java.math.BigInteger;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Scanner;
import javax.annotation.PostConstruct;
public class 压缩变换 {
/*
* 变换的过程如下:
* 从左到右枚举序列,每枚举到一个数字,如果这个数字没有出现过,刚将数字变换成它的相反数,如果数字出现过,则看它在原序列中最后的一次出现后面
* (且在当前数前面)出现了几种数字,用这个种类数替换原来的数字。
*
* 比如,序列(a1, a2, a3, a4, a5)=(1, 2, 2, 1, 2)在变换过程为: a1: 1未出现过,所以a1变为-1; a2:
* 2未出现过,所以a2变为-2; a3: 2出现过,最后一次为原序列的a2,在a2后、a3前有0种数字,所以a3变为0; a4:
* 1出现过,最后一次为原序列的a1,在a1后、a4前有1种数字,所以a4变为1; a5:
* 2出现过,最后一次为原序列的a3,在a3后、a5前有1种数字,所以a5变为1。 现在,给出原序列,请问,按这种变换规则变换后的序列是什么。
*
* 输入格式: 输入第一行包含一个整数n,表示序列的长度。 第二行包含n个正整数,表示输入序列。
*
* 输出格式: 输出一行,包含n个数,表示变换后的序列。
*
* 例如,输入: 5 1 2 2 1 2
*
* 程序应该输出: -1 -2 0 1 1
*
* 再例如,输入: 12 1 1 2 3 2 3 1 2 2 2 3 1
*
* 程序应该输出: -1 0 -2 -3 1 1 2 2 0 0 2 2
*
* 数据规模与约定 对于30%的数据,n<=1000; 对于50%的数据,n<=30000; 对于100%的数据,1
* <=n<=100000,1<=ai<=10^9
*
*
* 资源约定: 峰值内存消耗(含虚拟机) < 256M CPU消耗 < 3000ms
*/
public static void main(String[] args) {
int n,nowpost=0;//nowpost:当前位置
BigInteger temp;
Scanner sc = new Scanner(System.in);
LinkedList<BigInteger> a = new LinkedList<BigInteger>();
LinkedList<BigInteger> b = new LinkedList<BigInteger>();
LinkedHashMap<BigInteger, Integer> change = new LinkedHashMap<BigInteger, Integer>();//出现过的数,最后一次出现的位置
LinkedHashSet<BigInteger> set = new LinkedHashSet<BigInteger>();
n = sc.nextInt();
for(int i=0;i<n;i++){
a.add(sc.nextBigInteger());
}
LinkedList<BigInteger> copy = new LinkedList<BigInteger>(a);
while(!a.isEmpty()){//当源列表不为空时
temp = a.pop();
if(change.containsKey(temp)){//该数已经存在map中了,应更新value
//步骤:先向b中添加数,再更新a中的值(顺序不能变)
//先找出间隔的数的种类有多少
for(int i=change.get(temp)+1;i<nowpost;i++)
set.add(copy.get(i));
b.add(new BigInteger(set.size()+""));
//清空set
set.clear();
//更新a
change.remove(temp);
change.put(temp, nowpost);
}
else{//该数在map中不存在,应该创建一个
change.put(temp, nowpost);
//链表b添加数 0-temp [-temp]
b.add(BigInteger.ZERO.subtract(temp));
}
nowpost++;
}
while(!b.isEmpty()){
System.out.print(b.pop()+" ");
}
}
}