Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const int maxn = 6;
- struct fenwick {
- vector <int> t;
- int n;
- void init(int nn) {
- n = nn;
- t.assign(n, 0);
- }
- int sum(int r) {
- int result = 0;
- for (; r >= 0; r = (r & (r + 1)) - 1)
- result += t[r];
- return result;
- }
- void inc(int i, int delta) {
- for (; i < n; i = (i | (i + 1)))
- t[i] += delta;
- }
- int sum(int l, int r) {
- return sum(r) - sum(l - 1);
- }
- };
- struct seg_tree
- {
- seg_tree *l, *r;
- seg_tree() : l(0), r(0) {}
- vector <int> mt;
- fenwick mem;
- };
- void add(seg_tree * a, int tl, int tr, int pos, int tms)
- {
- if (tl + 1 == tr)
- {
- a->mt.push_back(tms);
- return;
- }
- int m = (tl + tr) / 2;
- if (pos < m)
- {
- if (a->l == nullptr)
- a->l = new seg_tree();
- add(a->l, tl, m, pos, tms);
- }
- else
- {
- if (a->r == nullptr)
- a->r = new seg_tree();
- add(a->r, m, tr, pos, tms);
- }
- }
- int get_sz(seg_tree * a)
- {
- if (a == nullptr)
- return 0;
- return a->mt.size();
- }
- int get_elem(seg_tree * a, int v)
- {
- if (a == nullptr)
- return INT_MAX;
- return a->mt[v];
- }
- void build(seg_tree * a, int l, int r)
- {
- if (a == nullptr)
- return;
- if (l + 1 == r)
- {
- sort(a->mt.begin(), a->mt.end());
- a->mem.init(a->mt.size());
- return;
- }
- int m = (l + r) / 2;
- build(a->l, l, m);
- build(a->r, m, r);
- a->mt.resize(get_sz(a->r) + get_sz(a->l));
- int ukL = 0, ukR = 0;
- for (int &j : a->mt)
- {
- if (ukL == get_sz(a->l) || (ukR != get_sz(a->r) && get_elem(a->r, ukR) < get_elem(a->l, ukL)))
- {
- j = get_elem(a->r, ukR++);
- }
- else
- {
- j = get_elem(a->l, ukL++);
- }
- }
- a->mem.init((int)a->mt.size() + 1);
- }
- void put(seg_tree *a, int tl, int tr, int pos, int tms)
- {
- a->mem.inc(lower_bound(a->mt.begin(), a->mt.end(), tms) - (a->mt).begin(), 1);
- if (tl + 1 == tr) return;
- int m = (tl + tr) / 2;
- if (pos < m)
- put(a->l, tl, m, pos, tms);
- else
- put(a->r, m, tr, pos, tms);
- }
- int ele(seg_tree * a, int tl, int tr, int l, int r, int tms)
- {
- if (a == nullptr)
- return 0;
- if (l <= tl && tr <= r)
- {
- return a->mem.sum(lower_bound(a->mt.begin(), a->mt.end(), tms) - (a->mt).begin() - 1);
- }
- else if (tl >= r || l >= tr)
- {
- return 0;
- }
- int m = (tl + tr) / 2;
- return ele(a->l, tl, m, l, r, tms) + ele(a->r, m, tr, l, r, tms);
- }
- struct cut
- {
- int tin = 0;
- struct req
- {
- int ybot, ytop, xleft, xright, num, aTime;
- char isPoint;
- req(int y1, int y2, int x1, int x2, char t, int pnum, int _time)
- {
- ybot = y1;
- ytop = y2;
- xleft = x1;
- xright = x2;
- isPoint = t;
- num = pnum;
- aTime = _time;
- }
- };
- vector <req> kek;
- vector <int> rofl;
- int ftype(req t)
- {
- if (t.isPoint)
- return 2;
- if (t.xleft <= t.xright)
- return 1;
- return 3;
- }
- int add_rect(int x1, int y1, int x2, int y2)
- {
- rofl.push_back(0);
- kek.push_back({y1, y2, x1, x2, 0, (int) rofl.size() - 1, ++tin});
- kek.push_back({y1, y2, x2, x1, 0, (int) rofl.size() - 1, tin});
- return (int) rofl.size() - 1;
- }
- void add_point(int x1, int y1)
- {
- kek.push_back({y1, y1, x1, x1, 1, -1, ++tin});
- }
- vector <int> calculated()
- {
- sort(kek.begin(), kek.end(), [&](const req &a,const req &b) { if (a.xleft != b.xleft) return a.xleft < b.xleft; return ftype(a) < ftype(b); });
- seg_tree * vint = new seg_tree();
- for (auto t : kek)
- {
- if (t.isPoint)
- {
- add(vint, -maxn, maxn, t.ybot, t.aTime);
- }
- }
- build(vint, -maxn + 1, maxn);
- for (auto i : kek)
- {
- if (ftype(i) == 1)
- {
- rofl[i.num] -= ele(vint, -maxn, maxn, i.ybot, i.ytop + 1, i.aTime);
- }
- else if (ftype(i) == 3)
- {
- rofl[i.num] += ele(vint, -maxn, maxn, i.ybot, i.ytop + 1, i.aTime);
- }
- else
- {
- put(vint, -maxn, maxn, i.ytop, i.aTime);
- }
- }
- return rofl;
- }
- };
- pair<int, int> rev(int x, int y)
- {
- return {y, -x};
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement