fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. pair <int, int> pa[100000];
  7. int t,n,l,r,f,k;
  8. cin>>t;
  9. for(int i=0;i<t;i++)
  10. {
  11. f=0;
  12. cin>>n;
  13. for(int j=0;j<n;j++)
  14. {
  15. cin>>pa[j].first>>pa[j].second;
  16. }
  17. sort(pa,pa+n);
  18. l=pa[0].first;
  19. r=pa[0].second;
  20. for(k=1;k<n;k++)
  21. {
  22. if(pa[k].first<=r)
  23. {
  24. if(pa[k].second>r)
  25. {
  26. r=pa[k].second;
  27. }
  28. }
  29. else
  30. {
  31. f=1;
  32. break;
  33. }
  34. }
  35. if(f==1)
  36. {
  37. for(int h=0;h<k;h++)\
  38. {
  39. cout<<1<<" ";
  40. }
  41. for(;k<n;k++)
  42. {
  43. cout<<2<<" ";
  44. }
  45. }
  46. else
  47. {
  48. cout<<-1;
  49. }
  50. cout<<"\n";
  51. }
  52. return 0;
  53. }
Success #stdin #stdout 0s 15896KB
stdin
1
3
1 1
1 1
2 2
stdout
1 1 2