inversion Sequence
problem ' s Link:
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1555
Mean:
Give you a sequence a[n], you want to construct a sequence B as required.
Sequence A[i] indicates that the number of I in sequence B preceded by a[i] is greater than I.
The conversion is:
A sequential sequence is known (1,2,3,4,...) and then tells us the number of each number in the sequence that precedes itself, and according to these conditions the sequence is adjusted to find a sequence that satisfies the condition.
Analyse:
STL Dafa is good. Insert directly with a vector.
Time Complexity:o (NLOGN)
Source Code:
//Memory Time//1347K 0MS//by:crazyacking//2015-03-29-23.24#include <map>#include<queue>#include<stack>#include<cmath>#include<cstdio>#include<vector>#include<string>#include<cstdlib>#include<cstring>#include<climits>#include<iostream>#include<algorithm>#defineMAXN 1000010#defineLL Long Longusing namespacestd;Const intMAXN =11111; intA[MAXN];intANS[MAXN]; vector<int>v; intMain () {//freopen ("data.in", "R", stdin); intN; while(SCANF ("%d", &n)! =EOF) { for(intI=0; i<n;i++) {scanf ("%d",&A[i]); } v.clear (); V.push_back (0); intok=1; for(inti=n-1; i>=0; i--) { if(V.size () <=A[i]) {OK=0; Break; } v.insert (V.begin ()+1+a[i],i+1); //for (int j=0;j<v.size (); j + +)//printf ("%d%c", V[j],j==v.size ()-1? ' \ n ': '); } if(OK) { for(intI=1; i<=n;i++) {printf ("%d%c", V[i],i==n?'\ n':' '); } }Else{puts ("No Solution"); } } return 0; } /************************************************************** problem:1555 user:crazyacking language:c+ + result:accepted time:164 Ms memory:1576 KB ***************************************************************< /c0>*/
View Code
STL or segment tree---CSU 1555:inversion Sequence