Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <set>
  5. #include <cstdio>
  6. #include <cmath>
  7. #include <algorithm>
  8.  
  9. using namespace std;
  10.  
  11. struct val
  12. {
  13. int x, y;
  14. };
  15.  
  16. val a[100050];
  17. int n, l, f[100050];
  18. map <int, int> m;
  19.  
  20. bool cmp (val a, val b)
  21. {
  22. return a.y < b.y;
  23. }
  24.  
  25. bool cmp2 (val a, val b)
  26. {
  27. if (a.x == b.x)
  28. {
  29. return a.y < b.y;
  30. }
  31. return a.x < b.x;
  32. }
  33.  
  34. void add (int i)
  35. {
  36. while (i <= n)
  37. {
  38. f[i]++;
  39. i = i + i - (i & (i - 1));
  40. }
  41. }
  42.  
  43. int sum (int i)
  44. {
  45. int ans = 0;
  46. while (i > 0)
  47. {
  48. ans += f[i];
  49. i = (i & (i - 1));
  50. }
  51. return ans;
  52. }
  53.  
  54. int main()
  55. {
  56. freopen ("input.txt", "r", stdin);
  57. freopen ("output.txt", "w", stdout);
  58. cin >> n;
  59. for (int i = 1; i <= n; i++)
  60. {
  61. cin >> a[i].x >> a[i].y;
  62. }
  63. sort (a + 1, a + n + 1, cmp);
  64. l = 1;
  65. for (int i = 1; i <= n; i++)
  66. {
  67. if (m[a[i].y] == 0) m[a[i].y] = l;
  68. else l--;
  69. l++;
  70. }
  71. sort (a + 1, a + n + 1, cmp2);
  72. for (int i = 1; i <= n; i++)
  73. {
  74. add (a[i].y);
  75. }
  76. for (int i = 0; i < l; i++)
  77. {
  78. cout << sum (i) << endl;
  79. }
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement