fork download
  1. //
  2. // Noszály Áron 9a Debreceni Fazekas Mihály Gimnázium
  3. // noszalyaron4@gmail.com
  4. //
  5. // g++ 5.4.0 -std=c++14
  6. //
  7. #include<bits/stdc++.h>
  8. #include<cstdlib>
  9.  
  10. using namespace std;
  11.  
  12. typedef long long ll;
  13. typedef unsigned long long ul;
  14. typedef long double ld;
  15.  
  16. #define all(s) (s).begin(),(s).end()
  17. #define pb push_back
  18. #define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  19. #define INF std::numeric_limits<int>::max()
  20. #define MINF std::numeric_limits<int>::min()
  21. #define tmax(a,b,c) max((a),max((b),(c)))
  22. #define tmin(a,b,c) min((a),min((b),(c)))
  23. #define vpii vector<pair<int,int>>
  24. #define vpll vector<pair<ll,ll>>
  25. #define mp make_pair
  26. #define xx first
  27. #define yy second
  28. #define sz(x) (int)(x).size()
  29.  
  30.  
  31.  
  32. #ifndef ONLINE_JUDGE
  33. # define LOG(x) (cerr << #x << " = " << (x) << endl)
  34. #else
  35. # define LOG(x) ((void)0)
  36. #endif
  37. const long double PI = acos(-1);
  38.  
  39. int d1[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
  40. int d2[8][2]={{1,0},{0,1},{0,-1},{-1,0},{1,1},{-1,1},{1,-1},{-1,-1}};
  41.  
  42. #define LENGYEL
  43.  
  44. struct PP {
  45. int x,y,i;
  46.  
  47. PP(int x_, int y_, int i_) {
  48. x=x_;
  49. y=y_;
  50. i=i_;
  51. }
  52.  
  53. bool operator<(const PP& b) const {
  54. if(y==b.y) return x<b.x;
  55. return y<b.y;
  56. }
  57. };
  58.  
  59. int ansx[10001],ansy[10001];
  60.  
  61. int main()
  62. {
  63. IO;
  64. int n;cin>>n;
  65. vector<PP> X,Y;
  66. for(int i=0;i<n;++i) {
  67. ansx[i]=ansy[i]=-1;
  68. int a,b,c,d;cin>>a>>b>>c>>d;
  69. X.pb(PP(a,c,i));
  70. Y.pb(PP(b,d,i));
  71. }
  72.  
  73. sort(all(X));
  74. sort(all(Y));
  75.  
  76. set<int> XX, YY;
  77. for(int i=1;i<=n;++i) {
  78. XX.insert(i);YY.insert(i);
  79. }
  80.  
  81.  
  82. for(int i=0;i<n;++i) {
  83.  
  84. set<int>::iterator it=XX.lower_bound(X[i].x);
  85. if(it==XX.end() || (*it)>X[i].y) {
  86. #ifdef LENGYEL
  87. cout<<"NIE\n";
  88. #else
  89. cout<<"-1\n";
  90. #endif
  91. return 0;
  92. }
  93.  
  94. ansx[X[i].i]=*it;
  95. XX.erase(it);
  96. }
  97.  
  98. for(int i=0;i<n;++i) {
  99. set<int>::iterator it=YY.lower_bound(Y[i].x);
  100. if(it==YY.end() || (*it)>Y[i].y) {
  101. #ifdef LENGYEL
  102. cout<<"NIE\n";
  103. #else
  104. cout<<"-1\n";
  105. #endif
  106. return 0;
  107. }
  108.  
  109. ansy[Y[i].i]=*it;
  110. YY.erase(it);
  111. }
  112.  
  113. for(int i=0;i<n;++i) {
  114. cout<<ansx[i]<<" "<<ansy[i]<<"\n";
  115. }
  116.  
  117.  
  118. return 0;
  119. }
  120.  
Runtime error #stdin #stdout 0s 4056KB
stdin
Standard input is empty
stdout
Standard output is empty