Advertisement
Emiliatan

c571

Mar 29th, 2019
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. /*  c571               */
  2. /*  AC (0.2s, 12.2MB)  */
  3. #include <cstdio>
  4. #include <vector>
  5. #include <algorithm>
  6. #define lowBit(x) (x) & (~(x)+1)
  7.  
  8. using namespace std;
  9.  
  10. const int MAXN = 100000;
  11. int n, ans[MAXN];
  12. int bit[MAXN]{};
  13.  
  14. inline void add(int x, int addition)
  15. {
  16.     while(x < n)
  17.     {
  18.         bit[x] += addition;
  19.         x += lowBit(x);
  20.     }
  21. }
  22. inline int query(int x)
  23. {
  24.     int res = 0;
  25.     while(x)
  26.     {
  27.         res += bit[x];
  28.         x -= lowBit(x);
  29.     }
  30.     return res;
  31. }
  32.  
  33. typedef struct point
  34. {
  35.     int y, z, id;
  36.     point(){}
  37.     point(int y, int z, int id):y(y), z(z), id(id) {}
  38. }pt;
  39. vector<vector<pt> > vec;
  40.  
  41. void D_C(int l, int r)
  42. {
  43.     if(r - l == 1) return;
  44.  
  45.     int mid = (l + r) >> 1;
  46.     D_C(l, mid); D_C(mid, r);
  47.  
  48.     vector<pt> lp, rp;
  49.     for(int i = l; i < mid; i++)
  50.         for(auto tmp : vec[i])
  51.             lp.emplace_back(tmp);
  52.     for(int i = mid; i < r; i++)
  53.         for(auto tmp : vec[i])
  54.             rp.emplace_back(tmp);
  55.  
  56.     sort(lp.begin(), lp.end(), [](const pt &a, const pt &b){return a.y < b.y;});
  57.     sort(rp.begin(), rp.end(), [](const pt &a, const pt &b){return a.y < b.y;});
  58.  
  59.     int index = 0;
  60.     for(auto tmp : rp)
  61.     {
  62.         while(index < lp.size() && tmp.y > lp[index].y)
  63.             add(lp[index++].z, 1);
  64.         ans[tmp.id] += query(tmp.z - 1);
  65.     }
  66.     for(int i = 0; i < index; i++)
  67.         add(lp[i].z, -1);
  68. }
  69. int main()
  70. {
  71.     scanf("%d", &n);
  72.     vec.resize(n);
  73.  
  74.     for(int i = 0, x, y, z; i < n; i++)
  75.     {
  76.         scanf("%d %d %d", &x, &y, &z);
  77.         vec[n - x].emplace_back(n - y + 1, n - z + 1, i);
  78.     }
  79.  
  80.     D_C(0, n);
  81.     for(int i = 0; i < n; putchar('\n'), i++)
  82.         printf("%d", ans[i]);
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement