Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <set>
- using namespace std;
- typedef struct event{
- int place;
- int add; /// in = 1 out = 2
- int height;
- bool operator < (const event &rhs)const{
- if(place == rhs.place){
- if(add == rhs.add){
- if(add == 1){
- return height > rhs.height;
- } else {
- return height < rhs.height;
- }
- } else {
- return add < rhs.add;
- }
- } else {
- return place < rhs.place;
- }
- }
- event(int p, int a, int h){
- place = p;
- add = a;
- height = h;
- }
- }event;
- int main(){
- int nb;
- scanf("%d", &nb);
- vector<event> tower;
- for(int i = 1; i <= nb; ++i){
- int s, e, h;
- scanf("%d", &s);
- scanf("%d", &e);
- scanf("%d", &h);
- tower.emplace_back(s, 1, h);
- tower.emplace_back(e, 2, h);
- }
- sort(tower.begin(), tower.end());
- multiset<int> curr = {0};
- int last = 0;
- for(auto t : tower){
- int p = t.place;
- int a = t.add;
- int h = t.height;
- if(a == 1){
- curr.insert(h);
- } else if(a == 2){
- curr.erase(curr.find(h));
- }
- multiset<int>::iterator itr;
- itr = curr.end();
- --itr;
- if(*itr != last){
- cout << p << " " << *itr << "\n";
- last = *itr;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment