Advertisement
Guest User

dsa

a guest
Apr 20th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <queue>
  4. #include <algorithm>
  5. using namespace std;
  6. int n,a,b,c,d,p=0;
  7. pair <pair <int,int>,int> pocz[500005];
  8. pair <pair <int,int>,int>  kon[500005];
  9. priority_queue <pair<int,int> >q;
  10. int t[500005][2];
  11.  
  12. int main(){
  13. scanf("%d",&n);
  14. for(int i=1;n>=i;i++)
  15. {
  16.     scanf("%d%d%d%d",&a,&b,&c,&d);
  17. pocz[i-1].first.first=a;
  18. pocz[i-1].first.second=c;
  19. kon[i-1].first.first=b;
  20. kon[i-1].first.second=d;
  21. pocz[i-1].second=i;
  22. kon[i-1].second=i;
  23. }
  24. sort(pocz,pocz+n);
  25. sort(kon,kon+n);
  26. for(int i=1;n>=i;i++)
  27. {
  28.     while(pocz[p].first.first==i)
  29.     {
  30.         q.push({pocz[p].first.second*-1,pocz[p].second});
  31.         p++;
  32.     }
  33.     pair <int,int> s=q.top();
  34.     q.pop();
  35.     t[s.second][0]=i;
  36. }
  37. p=0;
  38. for(int i=1;n>=i;i++)
  39. {
  40.     while(kon[p].first.first==i)
  41.     {
  42.         q.push({kon[p].first.second*-1,kon[p].second});
  43.         p++;
  44.     }
  45.     pair <int,int> s=q.top();
  46.     q.pop();
  47.     t[s.second][1]=i;
  48. }
  49. for(int i=1;n>=i;i++)
  50.     printf("%d %d\n",t[i][0],t[i][1]);
  51.  
  52.   return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement