Advertisement
Dang_Quan_10_Tin

Solar Lamps

Oct 10th, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. const int N = 2e5 + 5;
  6. int n, id1[N], id0[N], pos[N];
  7. struct Point
  8. {
  9.     ll x, y;
  10.     bool operator<(const Point &a) const
  11.     {
  12.         return x < a.x || (x == a.x && y < a.y);
  13.     }
  14. } s[2], a[N], b[N];
  15. int need[N], ans[N];
  16.  
  17. struct BIT
  18. {
  19.     int a[N];
  20.     void Update(int p)
  21.     {
  22.         for (; p <= n; p += p & -p)
  23.             ++a[p];
  24.     }
  25.     int Ans(int p)
  26.     {
  27.         int ans = 0;
  28.         for (; p > 0; p -= p & -p)
  29.             ans += a[p];
  30.         return ans;
  31.     }
  32.     int Get(int l, int r)
  33.     {
  34.         return Ans(r) - Ans(l - 1);
  35.     }
  36.     void clear()
  37.     {
  38.         memset(a, 0, sizeof a);
  39.     }
  40. } x;
  41.  
  42. void Read()
  43. {
  44.     cin >> n;
  45.     cin >> s[0].x >> s[0].y >> s[1].x >> s[1].y;
  46.     if (s[0].x * s[1].y - s[0].y * s[1].x < 0)
  47.         swap(s[0], s[1]);
  48.     for (int i = 1; i <= n; ++i)
  49.     {
  50.         cin >> a[i].x >> a[i].y;
  51.         id0[i] = id1[i] = pos[i] = i;
  52.     }
  53.     for (int i = 1; i <= n; ++i)
  54.     {
  55.         cin >> need[i];
  56.         ans[i] = i;
  57.     }
  58. }
  59.  
  60. ll dis(int t, int id)
  61. {
  62.     return s[t].y * a[id].x - s[t].x * a[id].y;
  63. }
  64.  
  65. void DoSort()
  66. {
  67.     if (s[1].y < 0 || (s[1].y == 0 && s[1].x < 0))
  68.     {
  69.         sort(id1 + 1, id1 + n + 1, [&](const int &i, const int &j) {
  70.             return dis(1, i) > dis(1, j);
  71.         });
  72.     }
  73.     else
  74.     {
  75.         sort(id1 + 1, id1 + n + 1, [&](const int &i, const int &j) {
  76.             return dis(1, i) < dis(1, j);
  77.         });
  78.     }
  79.     if (s[0].y < 0 || (s[0].y == 0 && s[0].x < 0))
  80.     {
  81.         sort(id0 + 1, id0 + n + 1, [&](const int &i, const int &j) {
  82.             return dis(0, i) < dis(0, j);
  83.         });
  84.     }
  85.     else
  86.     {
  87.         sort(id0 + 1, id0 + n + 1, [&](const int &i, const int &j) {
  88.             return dis(0, i) > dis(0, j);
  89.         });
  90.     }
  91. }
  92.  
  93. void Recursive(int l, int r, vector<int> &v)
  94. {
  95.     x.clear();
  96.     if (l == r)
  97.     {
  98.         if (!v.empty())
  99.             for (auto i : v)
  100.                 ans[i] = min(ans[i], l);
  101.         return;
  102.     }
  103.     if (v.empty() || l > r)
  104.         return;
  105.     vector<int> left, right;
  106.     sort(v.begin(), v.end(), [&](const int &x, const int &y) {
  107.         return b[x] < b[y];
  108.     });
  109.     int mid = (l + r) / 2, piv = 0;
  110.     for (int i = 1; i <= n; ++i)
  111.     {
  112.         if (piv < v.size() && v[piv] == pos[i])
  113.         {
  114.             if (pos[i] <= mid || x.Get(1, b[pos[i]].y) >= need[pos[i]])
  115.             {
  116.                 left.push_back(pos[i]);
  117.                 x.Update(b[pos[i]].y);
  118.             }
  119.             else
  120.                 right.push_back(pos[i]);
  121.             ++piv;
  122.         }
  123.         else if (pos[i] <= mid)
  124.             x.Update(b[pos[i]].y);
  125.         if (piv >= v.size())
  126.             break;
  127.     }
  128.     v.clear();
  129.     v.shrink_to_fit();
  130.     Recursive(l, mid, left);
  131.     Recursive(mid + 1, r, right);
  132. }
  133.  
  134. void Solve()
  135. {
  136.     DoSort();
  137.     vector<int> v;
  138.     for (int i = 1; i <= n; ++i)
  139.         v.push_back(i);
  140.     int cnt = 0;
  141.     for (int i = 1; i <= n; ++i)
  142.     {
  143.         int j = i;
  144.         ++cnt;
  145.         while (j <= n && dis(0, id0[i]) == dis(0, id0[j]))
  146.         {
  147.             b[id0[j]].x = cnt;
  148.             ++j;
  149.         }
  150.         i = j - 1;
  151.     }
  152.     cnt = 0;
  153.     for (int i = 1; i <= n; ++i)
  154.     {
  155.         int j = i;
  156.         ++cnt;
  157.         while (j <= n && dis(1, id1[i]) == dis(1, id1[j]))
  158.         {
  159.             b[id1[j]].y = cnt;
  160.             ++j;
  161.         }
  162.         i = j - 1;
  163.     }
  164.     sort(pos + 1, pos + n + 1, [&](const int &x, const int &y) {
  165.         return b[x] < b[y];
  166.     });
  167.     Recursive(1, n, v);
  168.     for (int i = 1; i <= n; ++i)
  169.         cout << ans[i] << " ";
  170. }
  171.  
  172. int32_t main()
  173. {
  174.     ios::sync_with_stdio(0);
  175.     cin.tie(0);
  176.     cout.tie(0);
  177.     Read();
  178.     Solve();
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement