Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
1.1 kB
0
Indexable
Never
#pragma GCC optimize("O2,no-stack-protector,unroll-loops")
#define ll long long
#define pb push_back
#define ipar(arr, n) vector<ll> arr(n); for(int i=1;i<=n;i++) cin>>arr[i];
#include <cmath>
#include <bits/stdc++.h>
#define pii pair<int, int>;
#define pll pair<ll, ll>;
using namespace std;

static bool cmp(pair<ll,ll>&a, pair<ll,ll>&b){
    return a.second>b.second;
}


void solve(){
    ll n;cin>>n;
    vector<ll>arr((2*n)+1);
    for(int i=1;i<=2*n;i++) cin>>arr[i];
    unordered_map<ll,vector<ll>>mp; //number, 2 indexes
    
    for(int i=1;i<=2*n;i++){
        mp[arr[i]].pb(i);
    }
    
    vector<pair<ll,ll>>idiff; //number , index difference
    for(int i=1;i<=n;i++){
        idiff.pb({i,abs(mp[i][1]-mp[i][0])}); //number ,diff
    }
    
    sort(idiff.begin(),idiff.end(),cmp);
    //for(auto i:idiff){
    //    cout<<i.first<<"-"<<i.second<<"\n";
    //}
    for(auto i:idiff){
        cout<<i.first<<" ";
    }
    cout<<"\n";
}


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
	cin>>t;
	while(t--) solve();
}
Leave a Comment