Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auto cmp = []( int b ,auto it)->bool {
- if( it.b > b)
- return true;
- return false;
- };
- auto cmp2 = []( auto it,int b )->bool {
- if( it.b < b)
- return true;
- return false;
- };
- int main()
- {
- ifstream file("data.txt");
- int N;
- file>>N;
- vector<line> l(N);
- for(int i = 0;i<N;++i){
- int b,e;
- file>>b>>e;
- line p;
- p.e = e;
- p.b = b;
- p.id = i;
- l[i] = p;
- }
- vector<line> cp = l;
- for(int i = 0;i<l.size();++i){
- cout<<l[i].b<<" "<<l[i].e<<" "<<l[i].id<<endl;
- }
- cout<<endl;
- for(int i = 0;i<l.size();++i){
- if(l[i].e >= l[i+1].e && l[i].b <= l[i+1].b ){
- line p;
- p.e = l[i].e;
- p.b = l[i+1].e+1;
- p.id = l[i].id;
- l[i].e = l[i+1].b-1;
- auto upper = std::upper_bound(l.begin(), l.end(), l[i+1].e , cmp );
- //cout<<l[i].e<<" "<<distance(l.begin()+i, upper)<<" "<< (*upper).b <<endl;
- if(p.e != p.b){
- l.emplace(l.begin()+i+distance(l.begin()+i, upper),p);
- }
- if(l[i].e < l[i].b ){
- l.erase (l.begin()+i);
- }
- }
- }
- cout<<endl;
- for(int i = 0;i<l.size();++i){
- cout<<l[i].b<<" "<<l[i].e<<" "<<l[i].id<<endl;
- }
- int n;
- file>>n;cout<<endl;
- for(int i=0;i<n;++i){
- int k;
- file>>k;
- auto upper = std::lower_bound(l.begin(), l.end(), k , cmp2 );
- cout<<(*upper).b<<" "<<(*upper).e<<" "<<k<<endl;
- if(cp[(*upper).id].b <= k && cp[(*upper).id].e >= k )
- cout<<(*upper).id+1<<endl;
- else
- cout<<-1<<endl;
- }
- // cout<<a1<<" "<<a2<<" "<<a3<<" "<<b1<<" "<<b2<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement