Advertisement
Guest User

Untitled

a guest
Jun 6th, 2016
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define F first
  4. #define S second
  5. #define pb push_back
  6. #define mp make_pair
  7.  
  8. using namespace std;
  9.  
  10. struct pair_comp {
  11.     bool operator() (pair<int,pair<int,int>>  const & a, pair<int,pair<int,int>>  const & b) {
  12.         return (a.F < b.F) || (a.F == b.F && a.S.F < b.S.F) || (a.F == b.F && a.S.F == b.S.F && a.S.S > b.S.S);
  13.     }
  14. };
  15.  
  16. int l, h, r;
  17. vector<pair<int,pair<int,int>>>pt;
  18. multiset<int>q;
  19.  
  20. int main() {
  21.  
  22.     // freopen("input.txt", "r", stdin);
  23.  
  24.     while(scanf("%d%d%d", &l, &h, &r) == 3) {
  25.         pt.pb(mp(l, mp(0, h)));
  26.         pt.pb(mp(r, mp(1, h)));
  27.     }
  28.    
  29.     sort(pt.begin(), pt.end(), pair_comp());
  30.  
  31.     if (pt[0].F > 1)
  32.         printf("1 0 ");
  33.  
  34.     q.insert(0);
  35.     for (int i = 0; i < pt.size(); i++) {
  36.         if (i && pt[i].S.F == 1 && pt[i-1].S.F == 1 && pt[i].F == pt[i-1].F && pt[i].S.S <= pt[i-1].S.S) {
  37.             q.erase(pt[i].S.S);
  38.             continue;
  39.         }
  40.         if (pt[i].S.F == 0) {
  41.             if (pt[i].S.S > *q.rbegin())
  42.                 printf("%d %d ", pt[i].F, pt[i].S.S);
  43.             q.insert(pt[i].S.S);
  44.         } else {
  45.             q.erase(pt[i].S.S);
  46.             if (*q.rbegin() >= pt[i].S.S)
  47.                 continue;
  48.             if (i + 1 < pt.size())
  49.                 printf("%d %d ", pt[i].F, *q.rbegin());
  50.             else
  51.                 printf("%d %d\n", pt[i].F, *q.rbegin());
  52.         }
  53.     }
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement