URAL 1707. Hypnotoad's Secret

space=1&num=1707" target="_blank" style="">题目链接

题意:这题设置的恶心不能多说。构造点和矩形。大概就是问每一个矩形里面是否包括点

思路:树状数组。把点排序,按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;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

URAL 1707. Hypnotoad&#39;s Secret(树阵)的更多相关文章

  1. ural 1707. Hypnotoad's Secret(线段树)

    题目链接:ural 1707. Hypnotoad's Secret 题目大意:给定N和M,然后N组s0, t0, Δs, Δt, k,每组能够计算出k个星星的坐标:M组a0, b0, c0, d0, ...

  2. BZOJ 3211 弗洛拉前往国家 树阵+并检查集合

    标题效果:给定一个序列,它提供了以下操作: 1.将[l.r]每个号码间隔a[i]变sqrt(a[i]) 2.查询[l,r]间隔和 剧烈的变化不支持由间隔,因此,我们选择单 - 点更换间隔查询的树阵,但 ...

  3. poj 2309 BST 使用树阵lowbit

    假设领悟了树阵lowbit,这个问题很简单,底部是奇数,使用lowbit(x)寻找x父亲,然后x父亲-1是的最大数量 至于lowbit问题是如何计算,寻找x父亲,事实上x+2^x二进制结束0的数量. ...

  4. HDOJ 5147 Sequence II 树阵

    树阵: 每个号码的前面维修比其数数少,和大量的这后一种数比他的数字 再枚举每一个位置组合一下 Sequence II Time Limit: 5000/2500 MS (Java/Others)    ...

  5. CJOJ 1976 二叉苹果树 / URAL 1018 Binary Apple Tree(树型动态规划)

    CJOJ 1976 二叉苹果树 / URAL 1018 Binary Apple Tree(树型动态规划) Description 有一棵苹果树,如果树枝有分叉,一定是分2叉(就是说没有只有1个儿子的 ...

  6. URAL 1822. Hugo II&#39;s War 树的结构+二分

    1822. Hugo II's War Time limit: 0.5 second Memory limit: 64 MB The glorious King Hugo II has declare ...

  7. hdu 3966 Aragorn&#39;s Story(树链剖分+树状数组)

    pid=3966" target="_blank" style="">题目链接:hdu 3966 Aragorn's Story 题目大意:给定 ...

  8. Codeforces 61E Enemy is weak 乞讨i&lt;j&lt;k &amp;&amp; a[i]&gt;a[j]&gt;a[k] 对数的 树阵

    主题链接:点击打开链接 意大利正在寻求称号 i<j<k && a[i]>a[j]>a[k] 的对数 假设仅仅有2元组那就是求逆序数的做法 三元组的话就用一个树状 ...

  9. nyoj 117 找到的倒数 【树阵】+【分离】

    这个问题的解决方案是真的很不错!!! 思路:建立一个结构体包括val和id. val就是输入的数,id表示输入的顺序.然后依照val从小到大排序.假设val相等.那么就依照id排序. 假设没有逆序的话 ...

随机推荐

  1. Ruby学习: 类变量和类方法

    一.类变量 在ruby中,可以为类定义类变量,类变量的值为类的所有实例(对象)所共享. 有点类似其它语言(如java)中的静态变量,但与java中的静态变量的区别是, 类变量是私有的,无法在类的外部访 ...

  2. cmake 学习笔记(四)

    接前面的一二三,学习一下 CMakeCache.txt 相关的东西. CMakeCache.txt 可以将其想象成一个配置文件(在Unix环境下,我们可以认为它等价于传递给configure的参数). ...

  3. Apache JMeter - load test tool

    What is it? ->>>> http://jmeter.apache.org/index.html  (Please read!) Where to get it? - ...

  4. leetcode先刷_Search in Rotated Sorted Array II

    上一页下一页,找到相同的旋转阵列的问题.假设数组元素一再怎么办呢?会发生什么? 我给大家举一个极端的例子.如果是这样的阵列中的元件.1,1,2,1,1,1,1,我们想看看这个数组2,刚开始A[midd ...

  5. javascript时间函数

    //时间函数 var myDate = new Date(); myDate.getYear();        //获取当前年份(2位) myDate.getFullYear();    //获取完 ...

  6. POJ1054 枚举【STL__binary_search()_的应用】

    ①使用binary_search前要先保证有序 ②binary_search函数仅返回true或false ③binary_search(first element, laste lment + 1, ...

  7. poj 1363 Rails in PopPush City &&【求堆栈中合法出栈顺序次数】

    问题如下: 问题 B: Rails 时间限制: Sec 内存限制: MB 提交: 解决: [提交][状态][讨论版] 题目描述 There is a famous railway station in ...

  8. Chapter 7 代理模式

    代理模式:为其它对象提供一种代理以控制对这个对象的访问. 代码: package xiao; class Girl{ private String name; public void setName( ...

  9. Windows Phone 8初学者开发—第17部分:Coding4Fun工具包简介

    原文 Windows Phone 8初学者开发—第17部分:Coding4Fun工具包简介 第17部分:Coding4Fun工具包简介 原文地址:  http://channel9.msdn.com/ ...

  10. js Function 加不加new 详解

    以下来自:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new The new operato ...