STL or segment tree---CSU 1555:inversion Sequence

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.