Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- size_t w, h;
- struct point {
- size_t x, y;
- };
- bool operator<(const point & p1, const point & p2) {
- return p1.x < p2.x;
- }
- struct vertex {
- vertex * l, * r;
- size_t sum;
- vertex(size_t val)
- : l(NULL), r(NULL), sum(val)
- { }
- vertex(vertex * l, vertex * r)
- : l(l), r(r), sum(0)
- {
- if (l) sum += l->sum;
- if (r) sum += r->sum;
- }
- };
- vertex * build(size_t tl, size_t tr) {
- if (tl == tr)
- return new vertex(0);
- int tm = (tl + tr) >> 1;
- return new vertex(
- build(tl, tm),
- build(tm + 1, tr)
- );
- }
- int get_sum(vertex * t, size_t tl, size_t tr, size_t l, size_t r) {
- if (l > r)
- return 0;
- if (l == tl && tr == r)
- return t->sum;
- size_t tm = (tl + tr) >> 1;
- return get_sum(t->l, tl, tm, l, min(r, tm)) + get_sum(t->r, tm + 1, tr, max(l, tm + 1), r);
- }
- vertex * update(vertex * t, size_t tl, size_t tr, size_t pos, size_t new_val) {
- if (tl == tr)
- return new vertex(new_val);
- size_t tm = (tl + tr) >> 1;
- if (pos <= tm)
- return new vertex(
- update(t->l, tl, tm, pos, new_val),
- t->r
- );
- else
- return new vertex(
- t->l,
- update(t->r, tm + 1, tr, pos, new_val)
- );
- }
- void next_coord(size_t k, size_t & xlp, size_t & xhp, size_t & ylp, size_t & yhp) {
- size_t x1 = ((xlp + k) * 13 + 7) % (w + 1);
- size_t x2 = ((xhp + k) * 7 + 13) % (w + 1);
- size_t y1 = ((ylp + k) * 13 + 7) % (h + 1);
- size_t y2 = ((yhp + k) * 7 + 13) % (h + 1);
- xlp = min(x1, x2);
- xhp = max(x1, x2);
- ylp = min(y1, y2);
- yhp = max(y1, y2);
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n = 0;
- cin >> w >> h >> n;
- vertex ** persistent_tree = new vertex *[w + 1];
- vector<point> sky = vector<point>(n);
- size_t x, y;
- for (int i = 0; i < n; ++i) {
- cin >> sky[i].x >> sky[i].y;
- }
- sort(sky.begin(), sky.end());
- persistent_tree[0] = build(0, h);
- int ind = 0;
- for (int i = 0; i <= w; ++i) {
- if (i != 0)
- persistent_tree[i] = persistent_tree[i - 1];
- while (ind < sky.size() && sky[ind].x == i) {
- int old = get_sum(persistent_tree[i], 0, h, sky[ind].y, sky[ind].y);
- persistent_tree[i] = update(persistent_tree[i], 0, h, sky[ind].y, old + 1);
- ++ind;
- }
- }
- size_t Q;
- cin >> Q;
- size_t xl = w >> 1;
- size_t xh = w;
- size_t yl = h >> 1;
- size_t yh = h;
- vector<size_t> answer = vector<size_t>(Q);
- answer[0] = get_sum(persistent_tree[xh], 0, h, yl, yh) - get_sum(persistent_tree[xl - 1], 0, h, yl, yh);
- for (int i = 1; i < Q; ++i) {
- next_coord(answer[i - 1], xl, xh, yl, yh);
- if (xl != 0)
- answer[i] = get_sum(persistent_tree[xh], 0, h, yl, yh) - get_sum(persistent_tree[xl - 1], 0, h, yl, yh);
- else
- answer[i] = get_sum(persistent_tree[xh], 0, h, yl, yh);
- }
- delete[] persistent_tree;
- for (size_t i = 0; i < answer.size(); ++i) {
- cout << answer[i] << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement