Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <stack>
  5. using namespace std;
  6.  
  7. bool comp(pair<int,int> p1, pair<int,int> p2){
  8.     if(p1.first>=p2.first){
  9.         return 0;
  10.     }
  11.     else{
  12.         if(p1.second>=p2.second){
  13.             return 0;
  14.         }
  15.         else{
  16.             return 1;
  17.         }
  18.     }
  19. }
  20.  
  21. int main(){
  22.     int n;
  23.     cin>>n;
  24.     vector<pair<int,int>> a;
  25.     for(int i=0;i<n;i++){
  26.         int x,v;
  27.         cin>>x>>v;
  28.         a.push_back(make_pair(x,v));
  29.     }
  30.     sort(a.begin(),a.end(),comp);
  31. //  for(auto i:a){
  32. //      cout<<i.first<<" "<<i.second<<"\n";
  33. //  }  
  34.     stack<int> st;
  35.     vector<int> a1;
  36.     for (int i=0;i<n;i++){
  37.         int x=a[i].first, v=a[i].second;
  38.         if (v==1){
  39.             st.push(x);
  40.         }
  41.         else{
  42.             if(!st.empty()){
  43.                 a1.push_back(x - st.top());
  44.                 st.pop();
  45.             }
  46.         }
  47.     }
  48.     sort(a1.begin(),a1.end());
  49. //  for(auto i:a1){
  50. //      cout<<i<<"\n";
  51. //  }
  52. //  map<int,int>
  53. //  stack<pair<int,int>> st1;
  54. //  for(int i=0;i<a.size();i++){
  55. //      if(st.empty()){
  56. //          st.push_back(a[i]);
  57. //          continue;
  58. //      }
  59. //      if(st.top().second != a[i].second){
  60. //         
  61. //      }
  62. //  }
  63.     int m;
  64.     cin>>m;
  65.     for (int i=0;i<m;i++) {
  66.         int time;cin>>time;
  67.         cout<<(n-((upper_bound(a1.begin(),a1.end(),time*2)-a1.begin())*2))<<"\n";
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement