Advertisement
cosenza987

Untitled

Mar 21st, 2023
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.38 KB | None | 0 0
  1. //Слава Україні, Героям слава
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. // random shit that apparently worked :D
  8. // 1st AC -> persistent li chao tree
  9. // 2nd AC -> parallel binary search + CHT
  10. // 3rd AC -> parallel binary search + li chao
  11.  
  12. const int N = 1e5 + 7, MAX = 1e9;
  13. const long long linf = 0x3f3f3f3f3f3f3f3f;
  14.  
  15. vector<pair<long long, long long>> pts, lines;
  16. vector<vector<int>> ans;
  17.  
  18. struct lichao {
  19.     struct line {
  20.         long long m, b;
  21.         long long operator()(long long x) const {
  22.             return m * x + b;
  23.         }
  24.         bool cmp(const line &a, long long x) {
  25.             return (*this)(x) < a(x);
  26.         }
  27.     };
  28.     vector<line> seg;
  29.     vector<int> L, R;
  30.     lichao() {
  31.         seg.push_back({0, -linf});
  32.         L.push_back(-1);
  33.         R.push_back(-1);
  34.     }
  35.     void add(line a, int p = 0, long long l = -MAX, long long r = MAX) {
  36.         long long mid = (l + r) >> 1;
  37.         if(seg[p].cmp(a, mid)) {
  38.             swap(seg[p], a);
  39.         }
  40.         if(a.b == -linf) {
  41.             return;
  42.         }
  43.         if(seg[p].cmp(a, l) != seg[p].cmp(a, mid)) {
  44.             if(L[p] == -1) {
  45.                 L[p] = seg.size();
  46.                 R.push_back(-1);
  47.                 L.push_back(-1);
  48.                 seg.push_back({0, -linf});
  49.             }
  50.             add(a, L[p], l, mid - 1);
  51.         } else if(seg[p].cmp(a, r) != seg[p].cmp(a, mid)) {
  52.             if(R[p] == -1) {
  53.                 R[p] = seg.size();
  54.                 R.push_back(-1);
  55.                 L.push_back(-1);
  56.                 seg.push_back({0, -linf});
  57.             }
  58.             add(a, R[p], mid + 1, r);
  59.         }
  60.     }
  61.     long long query(long long x, int p = 0, long long l = -MAX, long long r = MAX) {
  62.         if(p < 0) {
  63.             return -linf;
  64.         }
  65.         long long mid = (l + r) >> 1, calc = seg[p](x);
  66.         if(calc == -linf) {
  67.             return calc;
  68.         }
  69.         if(x < mid) {
  70.             return max(calc, query(x, L[p], l, mid - 1));
  71.         } else {
  72.             return max(calc, query(x, R[p], mid + 1, r));
  73.         }
  74.     }
  75. };
  76.  
  77. void bs(int l, int r, vector<int> &cand) {
  78.     if(l + 1 == r or cand.empty()) {
  79.         for(auto e : cand) {
  80.             ans[l].push_back(e);
  81.         }
  82.         return;
  83.     }
  84.     int mid = (l + r) >> 1;
  85.     lichao li;
  86.     for(int i = l; i < mid; i++) {
  87.         li.add({lines[i].first, lines[i].second});
  88.     }
  89.     vector<int> pode, npode;
  90.     for(auto e : cand) {
  91.         if(pts[e].second < li.query(pts[e].first)) {
  92.             pode.push_back(e);
  93.         } else {
  94.             npode.push_back(e);
  95.         }
  96.     }
  97.     bs(l, mid, pode);
  98.     vector<int>().swap(pode);
  99.     bs(mid, r, npode);
  100.     vector<int>().swap(npode);
  101. }
  102.  
  103. int main() {
  104.     ios_base::sync_with_stdio(false);
  105.     cin.tie(nullptr);
  106.     int n;
  107.     cin >> n;
  108.     pts.resize(n);
  109.     for(int i = 0; i < n; i++) {
  110.         cin >> pts[i].first >> pts[i].second;
  111.     }
  112.     int p;
  113.     cin >> p;
  114.     lines.resize(p);
  115.     ans.resize(p + 1);
  116.     for(int i = 0; i < p; i++) {
  117.         cin >> lines[i].first >> lines[i].second;
  118.     }
  119.     vector<int> cand(n);
  120.     iota(cand.begin(), cand.end(), 0);
  121.     bs(0, p + 1, cand);
  122.     for(int i = 0; i < p; i++) {
  123.         cout << ans[i].size() << " ";
  124.         for(auto e : ans[i]) {
  125.             cout << e + 1 << " ";
  126.         }
  127.         cout << "\n";
  128.     }
  129.     return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement