Advertisement
VladSmirN

Отрезки

Oct 20th, 2020
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. struct line {
  2.     int b,e,id;
  3. };
  4.  
  5. auto cmp = []( int b ,auto it)->bool {
  6.     if(  it.b > b)
  7.     return true;
  8.  
  9.     return false;
  10. };
  11.  
  12.  
  13. for(int i = 0;i<l.size();++i){
  14.  
  15.          if(l[i].e >= l[i+1].e && l[i].b <= l[i+1].b ){
  16.  
  17.  
  18.             line p;
  19.             p.e = l[i].e;
  20.             p.b = l[i+1].e+1;
  21.             p.id = l[i].id;
  22.  
  23.             l[i].e = l[i+1].b-1;
  24.  
  25.             auto upper = std::upper_bound(l.begin(), l.end(), l[i+1].e   ,  cmp );
  26.              //cout<<l[i].e<<" "<<distance(l.begin()+i, upper)<<" "<<    (*upper).b   <<endl;
  27.             if(p.e != p.b){
  28.                 l.emplace(l.begin()+i+distance(l.begin()+i, upper),p);
  29.             }
  30.             if(l[i].e < l[i].b ){
  31.                 l.erase (l.begin()+i);
  32.             }
  33.  
  34.  
  35.          }
  36.  
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement