URAL 1707. Hypnotoad's Secret(樹狀數組),uralhypnotoad

來源:互聯網
上載者:User

URAL 1707. Hypnotoad's Secret(樹狀數組),uralhypnotoad
URAL 1707. Hypnotoad's Secret

題目連結

題意:這題設定的噁心不能多說,構造點和矩形,大概就是問每個矩形裡面是否包含點

思路:樹狀數組,把點排序,按y軸,在按x軸,在按詢問,這樣每次遇到一個點就在相應的掃描線上加,遇到查詢就詢問出左邊到這個點位置的,就能預先處理出每個點左下角包含的點的個數,然後每個矩形再利用容斥原理去搞一下即可

代碼:

#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, &b0, &c0, &d0, &da, &db, &dc, &dd, &q);}} op[350];#define lowbit(x) (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 < 350; i++)mi7[i] = mi7[i - 1] * 7 % MOD;while (~scanf("%d%d", &n, &m)) {cnt.clear();pn = 0;memset(bit, 0, sizeof(bit));int s0, t0, ds, dt, k;while (m--) {scanf("%d%d%d%d%d", &s0, &t0, &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)];if (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 <= 20) {for (int j = 0; j < q; j++)printf("%d", save[j]);printf("\n");} else {ll out = 0;for (int j = 0; j < q; j++)out = (out + mi7[j] * save[j]) % MOD;printf("%lld\n", out);}}}return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.