Advertisement
Emiliatan

d847

Jul 22nd, 2019
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. /* d847             */
  2. /* AC (77ms, 252KB) */
  3. #pragma warning( disable : 4996 )
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <cstdint>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <cassert>
  10. #include <tuple>
  11. #define ios_jazz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  12.  
  13. using namespace std;
  14.  
  15. constexpr int Dir4[4][2] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };
  16. constexpr int Dir8[8][2] = { {-1, -1}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 1} };
  17. constexpr double EPS = 1e-9;
  18. const double PI = acos(-1);
  19.  
  20. using int16 = short;
  21. using uint16 = unsigned short;
  22. using uint = unsigned int;
  23. using int64 = long long;
  24. using uint64 = unsigned long long;
  25. using pii = pair<int, int>;
  26.  
  27. /* fast power */
  28. auto pow_fast_2 = [](int64 b) -> int64 { return 1 << b; };
  29.  
  30. template <typename T>
  31. T pow_fast(T x, int64 b) noexcept
  32. {
  33.     T tmp = 1;
  34.     while (b)
  35.     {
  36.         if (b & 0x1) tmp = x * tmp;
  37.         x = x * x;
  38.         b >>= 1;
  39.     }
  40.     return tmp;
  41. }
  42.  
  43. /* main code */
  44. auto lowerbit = [](int x) { return x & (-x); };
  45. int BIT[1002]{};
  46. void updata(int, int);
  47. int presum(int);
  48.  
  49. using tiii = tuple<int, int, int>;
  50. constexpr int MAXN = 10000;
  51. int N, x, y, ans[MAXN + 1];
  52. tiii pts[MAXN + 1];
  53.  
  54. int main()
  55. {
  56.     while (~scanf("%d", &N))
  57.     {
  58.         memset(BIT, 0, sizeof(int) * 1002);
  59.         assert(N <= 10000);
  60.         for (int i = 0; i < N; ++i)
  61.         {
  62.             scanf("%d %d", &x, &y);
  63.             assert(x >= 1 && x <= 1000 && y >= 1 && y <= 1000);
  64.             pts[i] = { x, y, i };
  65.             assert(i < MAXN + 1);
  66.         }
  67.         sort(pts, pts + N, [](const tiii& lhs, const tiii& rhs) {
  68.             if (get<0>(lhs) != get<0>(rhs)) return get<0>(lhs) < get<0>(rhs);
  69.             return get<1>(lhs) < get<1>(rhs);
  70.             });
  71.  
  72.         for (int i, l = 0, r = 1; r <= N; )
  73.         {
  74.             while (get<0>(pts[r - 1]) == get<0>(pts[r]) && r < N) ++r;
  75.             --r;
  76.             for (i = l; i <= r; ++i)
  77.                 ans[get<2>(pts[i])] = presum(get<1>(pts[i]) - 1);
  78.             for (i = l; i <= r; ++i)
  79.                 updata(get<1>(pts[i]), 1);
  80.             r += 2;
  81.             l = r - 1;
  82.         }
  83.  
  84.         for (int i = 0; i < N; ++i)
  85.             printf("%d\n", ans[i]);
  86.     }
  87.  
  88.     return 0;
  89. }
  90.  
  91. void updata(int index, int x)
  92. {
  93.     assert(index >= 0);
  94.     while (index <= 1001) BIT[index] += x, index += lowerbit(index);
  95. }
  96. int presum(int index)
  97. {
  98.     int res = 0;
  99.     while (index > 0)
  100.         res += BIT[index], index -= lowerbit(index);
  101.     return res;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement