URAL 1707. Hypnotoad ' s Secret (tree-like array)

Source: Internet
Author: User

URAL 1707. Hypnotoad ' s Secret

Topic links

Test instructions: This problem sets the nausea can not say more, constructs the point and the rectangle, probably is asks each rectangle inside whether contains the point

Idea: Tree-like array, sorting points, pressing the y-axis, in the x-axis, in accordance with the query, so that each encounter a point in the corresponding scan line plus, encountered queries on the left to the point of the location, you can preprocess the lower left corner of each point contains the number of points, and then each rectangle and then use the principle of the

Code:

#include <cstdio> #include <cstring> #include <algorithm> #include <map>using namespace std;  typedef long LONG ll;const int N = 1050005;const int M = 5005;const ll MOD = 200904040930 + 33;struct Point {int x, Y;bool Isop Point () {}point (int x, int y, bool isop) {this->x = X;this->y = Y;this->isop = Isop;}} P[n];bool CMP (Point A, point B) {if (a.y = = b.y) {if (a.x = = b.x) return A.isop < B.isop;return a.x < b.x;} return A.Y < B.y;} int pn;int N, m;struct OP {int a0, B0, C0, D0;int da, DB, DC, Dd;int q;void Read () {scanf ("%d%d%d%d%d%d%d%d%d", &a0, & Amp;b0, &c0, &d0, &da, &db, &AMP;DC, &AMP;DD, &q);}} OP[350]; #define LOWBIT (x) (x&) int bit[m];void Add (int x, int v) {while (x <= N) {bit[x] + = v;x + = lowbit (x);}} int get (int x) {int ans = 0;while (x) {ans + = bit[x];x-= lowbit (x);} return ans;} int get (int l, int r) {return get (R)-Get (L-1);} typedef pair<int, int> PII, #define MP (A, B) Make_pair (A, B) Map<pii, int> Cnt;int save[350];ll Mi7[350];int Main () {mi7[0] = 1;for (int i = 1; i <; i++) mi7[i] = mi7[i-1] * 7 mod;while (~SCANF ("%d%d", &n, &m)) {cnt.clear ();p n = 0;memset (bit, 0, sizeof (bit)), int s0, t0, ds, DT, K;while (m--) {scanf ("%d%d%d%d%d", &s0, &t0, & Amp;ds, &dt, &k); for (int i = 0; i < K; i++) {p[pn++] = point (S0, T0, false); S0 = ((S0 + DS)% n + N)% N;t0 = ((t0 + dt)% n + N)% n;}} scanf ("%d", &m); for (int i = 0; i < m; i++) {op[i].read (); int a0 = op[i].a0, B0 = op[i].b0, C0 = op[i].c0, D0 = op[  I].d0;int da = op[i].da, db = op[i].db, DC = OP[I].DC, DD = op[i].dd;int q = op[i].q;for (int j = 0; J < Q; j + +) {int a  = Min (a0, b0), B = Max (a0, b0), c = min (C0, d0), d = max (C0, D0);p [pn++] = Point (A-1, C-1, True);p [pn++] = point (b, C  -1, true);p [pn++] = Point (A-1, D, True);p [pn++] = point (b, D, true); a0 = ((a0 + da)% n + N)% N;b0 = ((b0 + db)% n + N)% n;c0 = ((C0 + DC)% n + N)% n;d0 = ((D0 + dd)% n + N)% n;}} Sort (p, p + PN, CMP); for (int i = 0; i < PN; i++) {if (P[i].isop) cnt[mp (p[i].x, p[i].y)] = Get (1, p[i].x + 1); else Add (p[i].x + 1, 1);} for (int i = 0; i < m; i++) {int a0 = op[i].a0, B0 = op[i].b0, C0 = op[i].c0, D0 = Op[i].d0;int da = op[i].da, db = op[ I].db, DC = OP[I].DC, DD = op[i].dd;int q = op[i].q;for (int j = 0; J < Q; j + +) {int a = min (a0, b0), B = Max (a0, B0), c = min (C0, d0), d = max (C0, d0), int tmp = CNT[MP (b, D)]-CNT[MP (A-1, D)]-CNT[MP (b, c-1)] + cnt[mp (A-1, C-1)];i F (tmp = = 0) save[j] = 0;else Save[j] = 1;A0 = ((a0 + da)% n + N)% N;b0 = ((b0 + db)% n + N)% n;c0 = ((C0 + DC)% n + N)% n;d0 = ((D0 + dd)% n + N)% n;} if (q <=) {for (int j = 0; J < Q; j + +) printf ("%d", Save[j]);p rintf ("\ n");} else {ll out = 0;for (int j = 0; J &lt ; Q J + +) out = (out + mi7[j] * save[j])% mod;printf ("%lld\n", Out);}} return 0;}


URAL 1707. Hypnotoad ' s Secret (tree-like array)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.