Advertisement
VladSmirN

cpp

Oct 20th, 2020
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. auto cmp = []( int b ,auto it)->bool {
  2.     if(  it.b > b)
  3.     return true;
  4.  
  5.     return false;
  6. };
  7.  
  8. auto cmp2 = []( auto it,int b )->bool {
  9.     if(  it.b < b)
  10.     return true;
  11.  
  12.     return false;
  13. };
  14. int main()
  15. {
  16.  
  17.  
  18.     ifstream file("data.txt");
  19.     int N;
  20.     file>>N;
  21.     vector<line> l(N);
  22.     for(int i = 0;i<N;++i){
  23.         int b,e;
  24.         file>>b>>e;
  25.         line p;
  26.         p.e = e;
  27.         p.b = b;
  28.         p.id = i;
  29.         l[i] = p;
  30.     }
  31.  
  32.     vector<line> cp = l;
  33.     for(int i = 0;i<l.size();++i){
  34.  
  35.        cout<<l[i].b<<" "<<l[i].e<<" "<<l[i].id<<endl;
  36.  
  37.     }
  38. cout<<endl;
  39.     for(int i = 0;i<l.size();++i){
  40.  
  41.          if(l[i].e >= l[i+1].e && l[i].b <= l[i+1].b ){
  42.  
  43.  
  44.             line p;
  45.             p.e = l[i].e;
  46.             p.b = l[i+1].e+1;
  47.             p.id = l[i].id;
  48.  
  49.             l[i].e = l[i+1].b-1;
  50.  
  51.             auto upper = std::upper_bound(l.begin(), l.end(), l[i+1].e   ,  cmp );
  52.              //cout<<l[i].e<<" "<<distance(l.begin()+i, upper)<<" "<<    (*upper).b   <<endl;
  53.             if(p.e != p.b){
  54.                 l.emplace(l.begin()+i+distance(l.begin()+i, upper),p);
  55.             }
  56.             if(l[i].e < l[i].b ){
  57.                 l.erase (l.begin()+i);
  58.             }
  59.  
  60.  
  61.          }
  62.  
  63.     }
  64.  
  65. cout<<endl;
  66.     for(int i = 0;i<l.size();++i){
  67.  
  68.        cout<<l[i].b<<" "<<l[i].e<<" "<<l[i].id<<endl;
  69.  
  70.     }
  71. int n;
  72. file>>n;cout<<endl;
  73. for(int i=0;i<n;++i){
  74. int k;
  75. file>>k;
  76.  
  77. auto upper = std::lower_bound(l.begin(), l.end(), k   ,  cmp2 );
  78. cout<<(*upper).b<<" "<<(*upper).e<<" "<<k<<endl;
  79. if(cp[(*upper).id].b <= k && cp[(*upper).id].e >= k )
  80.     cout<<(*upper).id+1<<endl;
  81. else
  82.     cout<<-1<<endl;
  83.  
  84. }
  85.  
  86.    // cout<<a1<<" "<<a2<<" "<<a3<<" "<<b1<<" "<<b2<<endl;
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.         return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement