Description
For sequence i1, I2, i3, ..., in, we set AJ to is the number of members in the sequence which is prior to J and greater to J at the same time. The sequence A1, A2, A3, ..., an are referred to as the inversion sequence of the original sequence (I1, I2, i3, ..., in). For example, sequence 1, 2, 0, 1, 0 are the inversion sequence of sequence 3, 1, 5, 2, 4. Your task is to the find a full permutation of 1~n, which is an original sequence of a given inversion sequence. If There is no permutation meets the conditions please output "no solution".
Input
There is several test cases.
Each test case contains 1 positive integers N on the first line. (1≤n≤10000).
followed in the next line are an inversion sequence A1, A2, A3, ..., an (0≤aj < N)
The input would finish with the end of file.
Output
For each case, please output the permutation of 1~n on one line. If There is no permutation meets the conditions, please output "no solution".
Sample Input
51 2 0 1 030 0 021 1
Sample Output
3 1 5 2 2 3No Solution
The title of the original has never been understood
In the given a[] sequence, a[i] is the number of numbers in the desired b[] sequence in front of I
Eg:5
4 3 1) 0 0
A[1]=4, that is, in B, 1 of the front of four is greater than 1, a[2]=3, that is, 2 of the front 3 is greater than 2 ... a[4]=0, that is 4 in front of the 0 number than 4 large
Then B[]:4 3 5 2 1
Time mem//264ms 2032kb//by orcz//2015/4/13/* topic meaning I never understood in the given a[] sequence, a[i] is in the desired b[] sequence in the number of I in front of I larger than I eg:5 4 3 1 0 0a[1]=4 , that is, in B, 1 of the front of four is greater than 1, a[2]=3, that is, 2 of the front 3 is greater than 2 ... a[4]=0, that is, 4 in front of the 0 is larger than 4 B[]:4 3 5 2 1*/#include <cstdio> #include < Cstring> #include <iostream>using namespace std;int rcd[10005];int ans[10005];int n;struct node{int l,r,len;} tree[4*10005];void Build (int v,int l,int r) {tree[v].l=l; Tree[v].r=r; tree[v].len=l-r+1; if (l==r) return; int mid= (L+R) >>1; Build (v*2,l,mid+1); Build (V*2+1,mid,r);} int query (int v,int k) {tree[v].len--; if (tree[v].l = = TREE[V].R) return TREE[V].L; if (k <= tree[2*v].len) return query (2*V,K); else query (2*v + 1,k-tree[2*v].len);} void Solve () {for (int i = 1;i <= n; ++i) cin>>rcd[i]; Build (1,n,1); int leap=0; int POS; for (int i = 1;i <= n; ++i) {if (Tree[1].len <= rcd[i]) {leap = 1;break;} pos = Query (1,rcd[i] + 1); Ans[pos] = i; } if (LEAP) cout<< "No Solution" <<endl; else {for (int i = n;i > 1;-i) printf ("%d", ans[i]); printf ("%d\n", Ans[1]);}} int main () {while (~SCANF ("%d", &n)) solve ();}
Inversion Sequence (CSU 1555)