Skip to content

Instantly share code, notes, and snippets.

@pankajmore
Created February 5, 2014 17:08
Show Gist options
  • Save pankajmore/8828472 to your computer and use it in GitHub Desktop.
Save pankajmore/8828472 to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <list>
#include <stack>
#include <map>
#include <string>
#include <cstdio>
#include <iostream>
#include <ostream>
#include <utility>
#include <cstring>
#include <istream>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <deque>
#include <limits>
#include <sstream>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <cstdio>
using namespace std;
using namespace __gnu_pbds;
typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
#define FOR(k,a,b) for(typeof(a) k=(a); k <= (b); ++k)
#define REP(k,a) for(int k=0; k < (a); ++k)
#define SZ(x) ((int)((x).size()))
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define MP make_pair
#define TR(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
typedef tree<
int, /* key type */
null_mapped_type, /* value type */
less<int>, /* comparison */
rb_tree_tag, /* for having an rb tree */
tree_order_statistics_node_update> order_set;
int main(int argc, char *argv[])
{
int T;
cin>>T;
for(int j=0;j<T;j++){
int n;
cin>>n;
vector <int> A(n,0);
for(int i=0;i<n;i++) cin>>A[i];
order_set S;
for(int i=n-1;i>=0;i++) {
int x = A[i];
A[i] = n - A[i] - (S.order_of_key(A[i]) +1);
S.insert(x);
}
set <int> R(A.begin(),A.end());
cout<<"Test : "<<(j+1)<<endl;
if(R.size() != n){
cout<<-1<<endl;
}
else {
for(int i=0;i<n;i++) cout<<A[i]<<" ";cout<<endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment