mickypinata

SMMR-T236: Missing Skyline

Jun 22nd, 2020 (edited)
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. using namespace std;
  6.  
  7. typedef struct event{
  8.     int place;
  9.     int add; /// in = 1 out = 2
  10.     int height;
  11.     bool operator < (const event &rhs)const{
  12.         if(place == rhs.place){
  13.             if(add == rhs.add){
  14.                 if(add == 1){
  15.                     return height > rhs.height;
  16.                 } else {
  17.                     return height < rhs.height;
  18.                 }
  19.             } else {
  20.                 return add < rhs.add;
  21.             }
  22.         } else {
  23.             return place < rhs.place;
  24.         }
  25.     }
  26.     event(int p, int a, int h){
  27.         place = p;
  28.         add = a;
  29.         height = h;
  30.     }
  31. }event;
  32.  
  33. int main(){
  34.  
  35.     int nb;
  36.     scanf("%d", &nb);
  37.     vector<event> tower;
  38.     for(int i = 1; i <= nb; ++i){
  39.         int s, e, h;
  40.         scanf("%d", &s);
  41.         scanf("%d", &e);
  42.         scanf("%d", &h);
  43.         tower.emplace_back(s, 1, h);
  44.         tower.emplace_back(e, 2, h);
  45.     }
  46.     sort(tower.begin(), tower.end());
  47.  
  48.     multiset<int> curr = {0};
  49.     int last = 0;
  50.     for(auto t : tower){
  51.         int p = t.place;
  52.         int a = t.add;
  53.         int h = t.height;
  54.         if(a == 1){
  55.             curr.insert(h);
  56.         } else if(a == 2){
  57.             curr.erase(curr.find(h));
  58.         }
  59.         multiset<int>::iterator itr;
  60.         itr = curr.end();
  61.         --itr;
  62.         if(*itr != last){
  63.             cout << p << " " << *itr << "\n";
  64.             last = *itr;
  65.         }
  66.     }
  67.  
  68.  
  69.     return 0;
  70. }
Add Comment
Please, Sign In to add comment