Untitled
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int N = 1e9 + 7; template <typename T> istream& operator>>(istream& in, vector<T>& a){for(T& x : a){in >> x;}return in;} void solve() { int n; cin>>n; vector<int>a(n); cin>>a; vector<int>b(n); vector<int>vis(10000); for(int i=0; i<n; i++)b[i]=1; if(n<4){cout<<-1<<endl;return;} int count=0; for(int i=0; i<n; i++){ for(int j=i+1; j<n; j++){ if(a[i]==a[j]&&!vis[a[i]]){ if(count==2)break; vis[a[i]]=1; count++; if(count==1)b[i]=2; else if(count==2) b[i]=3; break; } } if(count>2){ break; } } if(count==2){ for(int i=0; i<n; i++)cout<<b[i]<<" "; cout<<endl; } else cout<<-1<<endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; cin >> t; while (t--) solve(); }
Leave a Comment