去年金华的题,现场看了一下就直接放下了。这题是直接构造答案就好了:
c[i]来自两部分,[-i+1,-1]和[i+1,n]。如果当前c[i]==0,且i最小,则说明这两段都没有比i公司要大的了,并且如果在[1,i-1]这段区间如果有比i还要大的话,那么这个i肯定不是让c[i]等于0的最小的i。所以如果当前有最小的i使c[i]==0,那么i为当前最大。如果没有的话,取最小的c[i],这些比他大的公司都来自于[-1+1,-1]这一段,所以……
[trick] 最后一个数字后面还有空格……
/*
Author : Speedcell
Update : 2013-10-16
Version : soppYcell 2.4
*/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#include <memory>
#include <complex>
#include <numeric>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <assert.h>
#include <locale.h>
using namespace std;
#pragma pack(4)
#ifndef __CONSTANT__
#define __CONSTANT__
typedef long long LONG;
const double pi = acos(-1.0);
const int inf = 0x7f7f7f7f;
const LONG INF = 0x7f7f7f7f7f7f7f7fll;
const int go[8][2] = {{0,1},{0,-1},{1,0},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
#endif // __CONSTANT__
#ifndef __IO__
#define __IO__
inline bool RD(int & a) {return scanf("%d",&a)!=EOF;}
inline bool RD(char & a) {return scanf("%c",&a)!=EOF;}
inline bool RD(char * a) {return scanf("%s", a)!=EOF;}
inline bool RD(double & a) {return scanf("%lf",&a)!=EOF;}
inline bool RD(LONG & a) {return scanf("%I64d",&a)!=EOF;}
template<class T1> inline bool
IN(T1 & a) {return RD(a);}
template<class T1,class T2> inline bool
IN(T1 & a,T2 & b) {return RD(a)&&RD(b);}
template<class T1,class T2,class T3> inline bool
IN(T1 & a,T2 & b,T3 & c) {return RD(a)&&RD(b)&&RD(c);}
template<class T1,class T2,class T3,class T4> inline bool
IN(T1 & a,T2 & b,T3 & c,T4 & d) {return RD(a)&&RD(b)&&RD(c)&&RD(d);}
template<class T1,class T2,class T3,class T4,class T5> inline bool
IN(T1 & a,T2 & b,T3 & c,T4 & d,T5 & e) {return RD(a)&&RD(b)&&RD(c)&&RD(d)&&RD(e);}
template<class T1,class T2,class T3,class T4,class T5,class T6> inline bool
IN(T1 & a,T2 & b,T3 & c,T4 & d,T5 & e,T6 & f) {return RD(a)&&RD(b)&&RD(c)&&RD(d)&&RD(e)&&RD(f);}
template<class T1,class T2,class T3,class T4,class T5,class T6,class T7> inline bool
IN(T1 & a,T2 & b,T3 & c,T4 & d,T5 & e,T6 & f,T7 & g) {return RD(a)&&RD(b)&&RD(c)&&RD(d)&&RD(e)&&RD(f)&&RD(g);}
inline void PT(int a) {printf("%d",a);}
inline void PT(char a) {printf("%c",a);}
inline void PT(char * a) {printf("%s",a);}
inline void PT(double a) {printf("%f",a);}
inline void PT(unsigned a) {printf("%u",a);}
inline void PT(LONG a) {printf("%I64d",a);}
inline void PT(string a) {printf("%s",a.c_str());}
inline void PT(const char a[]) {printf("%s",a);}
template<class T1> inline void
OT(T1 a) {PT(a);}
template<class T1,class T2> inline void
OT(T1 a,T2 b) {PT(a),PT(' '),PT(b);}
template<class T1,class T2,class T3> inline void
OT(T1 a,T2 b,T3 c) {PT(a),PT(' '),PT(b),PT(' '),PT(c);}
template<class T1,class T2,class T3,class T4> inline void
OT(T1 a,T2 b,T3 c,T4 d) {PT(a),PT(' '),PT(b),PT(' '),PT(c),PT(' '),PT(d);}
template<class T1,class T2,class T3,class T4,class T5> inline void
OT(T1 a,T2 b,T3 c,T4 d,T5 e) {PT(a),PT(' '),PT(b),PT(' '),PT(c),PT(' '),PT(d),PT(' '),PT(e);}
template<class T1,class T2,class T3,class T4,class T5,class T6> inline void
OT(T1 a,T2 b,T3 c,T4 d,T5 e,T6 f) {PT(a),PT(' '),PT(b),PT(' '),PT(c),PT(' '),PT(d),PT(' '),PT(e),PT(' '),PT(f);}
template<class T1,class T2,class T3,class T4,class T5,class T6,class T7> inline void
OT(T1 a,T2 b,T3 c,T4 d,T5 e,T6 f,T7 g) {PT(a),PT(' '),PT(b),PT(' '),PT(c),PT(' '),PT(d),PT(' '),PT(e),PT(' '),PT(f),PT(' '),PT(g);}
template<class T1> inline void
OL(T1 a) {OT(a),PT('\n');}
template<class T1,class T2> inline void
OL(T1 a,T2 b) {OT(a,b),PT('\n');}
template<class T1,class T2,class T3> inline void
OL(T1 a,T2 b,T3 c) {OT(a,b,c),PT('\n');}
template<class T1,class T2,class T3,class T4> inline void
OL(T1 a,T2 b,T3 c,T4 d) {OT(a,b,c,d),PT('\n');}
template<class T1,class T2,class T3,class T4,class T5> inline void
OL(T1 a,T2 b,T3 c,T4 d,T5 e) {OT(a,b,c,d,e),PT('\n');}
template<class T1,class T2,class T3,class T4,class T5,class T6> inline void
OL(T1 a,T2 b,T3 c,T4 d,T5 e,T6 f) {OT(a,b,c,d,e,f),PT('\n');}
template<class T1,class T2,class T3,class T4,class T5,class T6,class T7> inline void
OL(T1 a,T2 b,T3 c,T4 d,T5 e,T6 f,T7 g) {OT(a,b,c,d,e,f,g),PT('\n');}
#endif // __IO__
#ifndef __MACRO__
#define __MACRO__
#define ML(times) int tcase; IN(tcase); FOR(times,1,tcase)
#define FOR(i,a,b) for(int i=int(a),_##i=int(b);i<=_##i;i++)
#define DWN(i,b,a) for(int i=int(b),_##i=int(a);_##i<=i;i--)
#define ECH(i,u,pre,next) for(int i=int(pre[u]);i!=-1;i=int(next[i]))
#define MEM(a,v) memset(a,v,sizeof(a))
#define CLR(a,v) FOR(_i##a,0,sizeof(a)/sizeof(a[0])-1) a[_i##a]=v
#define LOOP(a,n) \
FOR(_i##a,0,(n)-1) \
OT(a[_i##a]),OT(_i##a!=__i##a?' ':'\n')
#define LOOP2(a,n,m) \
FOR(_i##a,0,(n)-1) FOR(_j##a,0,(m)-1) \
OT(a[_i##a][_j##a]),OT(_j##a!=__j##a?' ':'\n')
#define LOOPG(G,n,pre,next) \
FOR(_i##a,0,(n)-1) ECH(_j##a,_i##a,pre,next) \
OL(_i##a,G[_j##a].v,G[_j##a].w)
#endif // __MACRO__
#ifndef __BIT__
#define __BIT__
template<class T> inline T lb(T i) {return i&-i;}
template<class T> inline T lc(T i) {return i<<1;}
template<class T> inline T rc(T i) {return i<<1|1;}
template<class T> inline T at(T a,int i) {return a& (T(1)<<i);}
template<class T> inline T nt(T a,int i) {return a^ (T(1)<<i);}
template<class T> inline T s1(T a,int i) {return a| (T(1)<<i);}
template<class T> inline T s0(T a,int i) {return a&~(T(1)<<i);}
#endif // __BIT__
#ifndef __COMPARER__
#define __COMPARER__
const double eps = 1e-8;
inline int cmp(double a,double b=0) {return fabs(b-a)<eps?0:((b-a)<eps?+1:-1);}
template<typename type> inline int cmp(type a,type b=0) {return a==b?0:(b<a?+1:-1);}
template<typename type> inline bool gt(type a,type b) {return cmp(a,b)> 0;}
template<typename type> inline bool ge(type a,type b) {return cmp(a,b)>=0;}
template<typename type> inline bool eq(type a,type b) {return cmp(a,b)==0;}
template<typename type> inline bool ne(type a,type b) {return cmp(a,b)!=0;}
template<typename type> inline bool le(type a,type b) {return cmp(a,b)<=0;}
template<typename type> inline bool ls(type a,type b) {return cmp(a,b)< 0;}
template<typename type> inline type smax(type a,type b) {return gt(a,b)?a:b;}
template<typename type> inline type smin(type a,type b) {return ls(a,b)?a:b;}
#endif // __COMPARER__
const int MAXV = 240000;
class SegmentTree
{
private:
int L,R,val[MAXV<<2],label[MAXV<<2],lazy[MAXV<<2];
#define ls(l,r,i) l,(l+r)/2,lc(i)
#define rs(l,r,i) (l+r)/2+1,r,rc(i)
void add(int v,int l,int r,int i)
{
if(l<=r) val[i]+=v,lazy[i]+=v;
}
void down(int l,int r,int i)
{
if(l<r&&lazy[i])
{
add(lazy[i],ls(l,r,i));
add(lazy[i],rs(l,r,i));
lazy[i]=0;
}
}
void up(int l,int r,int i)
{
if(l<r)
{
if(val[lc(i)]<=val[rc(i)])
{
val[i]=val[lc(i)];
label[i]=label[lc(i)];
}
else
{
val[i]=val[rc(i)];
label[i]=label[rc(i)];
}
}
}
void update_set(int x,int v,int l,int r,int i)
{
if(x==l&&r==x) val[i]=v,label[i]=x;
else
{
down(l,r,i);
if(x<=(l+r)/2) update_set(x,v,ls(l,r,i));
else update_set(x,v,rs(l,r,i));
up(l,r,i);
}
}
void update_add(int x,int y,int v,int l,int r,int i)
{
if(x<=l&&r<=y) add(v,l,r,i);
else
{
down(l,r,i);
if(x<=(l+r)/2) update_add(x,y,v,ls(l,r,i));
if((l+r)/2<y) update_add(x,y,v,rs(l,r,i));
up(l,r,i);
}
}
public:
void clear(int l,int r)
{
L=l;
R=r;
MEM(lazy,0);
MEM(val,inf);
MEM(label,inf);
}
void update_set(int x,int v)
{
update_set(x,v,L,R,1);
}
void update_add(int x,int y,int v)
{
if(x<=y) update_add(x,y,v,L,R,1);
}
int query_val(void)
{
return val[1];
}
int query_label(void)
{
return label[1];
}
}st;
deque<int> a,b;
int n,c,ans[MAXV];
bool solve(void)
{
while(!a.empty()) a.pop_front();
while(!b.empty()) b.pop_front();
FOR(i,1,n)
{
int v=st.query_label();
int w=st.query_val();
if(w==0)
{
a.push_back(v);
b.push_back(-v);
st.update_add(1,v-1,-1);
st.update_set(v,inf);
}
else if(w>0)
{
if(b.empty()) return false;
else
{
i--;
v=b.front();
b.pop_front();
a.push_back(v);
st.update_add(-v+1,n,-1);
}
}
else return false;
}
return true;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("IT Companies.txt","r",stdin);
#else
#endif
while(IN(n),n)
{
st.clear(1,n);
FOR(i,1,n) IN(c),st.update_set(i,c);
if(!solve()) OL("Impossible");
else
{
while(!b.empty())
{
a.push_back(b.front());
b.pop_front();
}
int cnt=0;
while(!a.empty())
{
ans[cnt++]=a.back();
a.pop_back();
}
FOR(i,0,cnt-1) OT(ans[i],"");
OL("");
}
}
return 0;
}