Advertisement
Guest User

Untitled

a guest
Aug 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include<vector>
  2. #include<map>
  3. #include<iostream>
  4. #include<string>
  5. #include<algorithm>
  6.  
  7. using namespace std;
  8. struct point {
  9. int x;
  10. int type;
  11. point(int x, int type) : x(x), type(type) {}
  12. point() {}
  13. bool operator< (const point& Point) const {
  14. if(x < Point.x) {
  15. return type > Point.type;
  16. } else {
  17. return x < Point.x;
  18. }
  19.  
  20. }
  21. };
  22.  
  23.  
  24. int main() {
  25. int n, m,tmp;
  26. cin >> n >> m;
  27. vector<point>a(n * 2 + m);
  28. map<int,int>ans;
  29. vector<int>key(m);
  30.  
  31. for (int i = 0; i < n * 2; i+=2) {
  32. cin >> a[i].x >> a[i+1].x;
  33. if (a[i].x < a[i+1].x) {
  34. a[i].type = 1;
  35. a[i+1].type = -1;
  36. } else {
  37. a[i].type = -1;
  38. a[i+1].type = 1;
  39. }
  40. tmp = i + 2;
  41. }
  42. for (int i = 0; tmp < n * 2 + m; tmp++) {
  43. cin >> a[tmp].x;
  44. ans[a[tmp].x] = 0;
  45. key[i] = a[tmp].x;
  46. a[tmp].type = 0;
  47. i++;
  48. }
  49. sort(a.begin(),a.end());
  50.  
  51. for (int i = 0; i < n * 2 + m; i++)
  52. cout << a[i].x << " ";
  53.  
  54. cout << endl;
  55.  
  56. for (int i = 0; i < n * 2 + m; i++)
  57. cout << a[i].type << " ";
  58.  
  59. cout << endl;
  60. int bal = 0;
  61.  
  62. for (int i = 0; i < n * 2 + m; i++) {
  63.  
  64. if (a[i].type == 0) {
  65. ans[a[i].x] = bal;
  66. cout << a[i].x << " " << bal << endl;
  67. }
  68. bal+=a[i].type;
  69. }
  70. for (int i = 0; i < m; i++)
  71. cout << ans[key[i]] << " ";
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement