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. JavaEE Tutorials (7) - 在会话bean中使用异步方法调用

    7.1异步方法调用88 7.1.1创建异步业务方法88 7.1.2从企业bean客户端调用异步方法897.2async示例应用90 7.2.1async—war模块的架构91 7.2.2运行async ...

  2. 设置outlook自动回复

    当有同事需要出差时,或者不能即时回复邮件时,可用此功能. 下面列出设置步骤: 1.  首先,在桌面新建一个用以保存模板的文件夹,例如:emaii. 2.  新建一封邮件,输入你要自动回复的内容.另存为 ...

  3. ViewPager实现启动引导页面(个人认为很详细)

    效果如图: 启动页面是一张图片+延时效果,这里就不给出布局文件了. WelcomeActivity分析:在启动页面检测是否是第一次运行程序,如果是,则先跳转到引导界面的Activity——AndyVi ...

  4. Ural 1068 - Sum

    Your task is to find the sum of all integer numbers lying between 1 and N inclusive. Input The input ...

  5. QTexstStream的操作对象是QIODevice(因此QFile,QBuffer,QProcess,QTcpSocket都可以使用),或者QString

    QTexstStream用于读写纯文本以及HTML,XML等文本格式的文件,此类考虑了Unicode编码与系统本地编码的或其它任意编码之间的转换问题,别且明确地处理了因使用不同的操作系统而导致的行尾符 ...

  6. 鼠标滑轮一滚动Excel就停止工作

    鼠标滑轮一滚动Excel就停止工作 问题签名: 问题事件名称:APPCRASH 应用程序名:EXCEL.EXE 应用程序版本:15.0.4420.1017 应用程序时间戳:50673286 故障模块名 ...

  7. 为什么要用BASE64

    BASE64和其他相似的编码算法通常用于转换二进制数据为文本数据,其目的是为了简化存储或传输.更具体地说,BASE64算法主要用于转换二进 制数据为ASCII字符串格式.Java语言提供了一个非常好的 ...

  8. Spring Boot 探索系列 - 自动化配置篇

    26. Logging Prev  Part IV. Spring Boot features  Next 26. Logging Spring Boot uses Commons Logging f ...

  9. 百度编辑器ueditor简单易用

    最近刚刚被分配任务给一个新闻发布,它采用了富文本编辑器.本人也被用于,只是这一次我选择了百度的富文本编辑器ueditor1_4_3-utf8-jsp版. 事实上看ueditor功能非常强大,只是百度的 ...

  10. AsyncTask使用须知

    AsyncTask的实现原理就是封装了的线程池,详细见AsyncTask实现原理. 在1.5中初始引入的时候, AsyncTask 运行( AsyncTask.execute() )起来是顺序的,当同 ...