Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <set>
  5. #include <unordered_map>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <iterator>
  9.  
  10. using namespace std;
  11.  
  12. struct Point{
  13. int val;
  14. int type;
  15.  
  16. Point(int val = 0, int type = 0) :
  17. val(val), type(type){}
  18.  
  19. void set(int vall, int type)
  20. {
  21. this->val = vall;
  22. this->type = type;
  23. }
  24.  
  25. bool operator<(const Point& p) const
  26. {
  27. if(val == p.val)
  28. {
  29. return type > p.type;
  30. }
  31. return val < p.val;
  32. }
  33. };
  34.  
  35. int main() {
  36. int numInt;
  37. int q;
  38. cin >> numInt >> q;
  39. numInt *= 2;
  40.  
  41. multiset<Point> ms;
  42. int temp;
  43. int type;
  44. int cnt = 0;
  45. while(numInt--)
  46. {
  47. cin >> temp;
  48. cnt++;
  49. if(cnt % 2 == 1)
  50. {
  51. type = 1;
  52. }
  53. else
  54. type = -1;
  55.  
  56. Point p(temp, type);
  57. ms.insert(p);
  58. }
  59.  
  60. vector<int> quiries(q);
  61. int tempQuiy;
  62.  
  63. for(int i = 0; i < q; i++)
  64. {
  65. cin >> tempQuiy;
  66. quiries[i] = tempQuiy;
  67. ms.insert(tempQuiy);
  68. }
  69.  
  70. unordered_map<int, int> holder;
  71. auto it = ms.begin();
  72. int numActiveInt = 0;
  73. while(it != ms.end())
  74. {
  75. numActiveInt += it->type;
  76. if(it->type == 0)
  77. {
  78. holder[it->val] = numActiveInt;
  79. }
  80. it++;
  81. }
  82.  
  83. for(int i = 0; i < q; i++)
  84. {
  85. auto iter = holder.find(quiries[i]);
  86. if(iter != holder.end())
  87. cout << iter->second << " ";
  88. }
  89.  
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement