Problem C: reverse order 1

Time Limit: 1 Sec  Memory Limit: 128 MB
Submissions: 545  Solved: 95
Description

Here is a sequence a1..n, which is a disordered sequence from 1 to N. If i < j and ai > aj, then <i, j> is called a pair of inversion. And b1..n-1 is defined as follows, bk is the number of the total inversion pairs in array a, when i<=k<j. Now the array b is required while the array a is known.

Input

Several cases end with the end of the file;

And each of the cases includes two lines, a integer n(2<=n<=10^5)in the first line, and the second line followed with n integer, which is in the presentation of array a;

Output

Output the answer of each case in a line, namely the array b, and a space is required between the adjacent integers.

Sample Input

5
3 1 4 2 5
Sample Output

2 1 2 0
这题原本做法很复杂,要用树状dp,但wly的找规律解法让我大开眼界

#include<stdio.h>
int main()
{
	int a[100005];
	int t,i;
	long long s;
	while(scanf("%d",&t)!=EOF)
	{
		  s=0;
		for(i=1;i<=t;i++)
		 scanf("%d",a+i);
		for(i=1;i<t;i++)
		{
			s+=a[i]-i;
	    	if(i==1)
	    	 printf("%lld",s);
	    	 else
	    	 printf(" %lld",s);
		}
	  printf("\n");
	}
}