URAL 1707. Hypnotoad's Secret(树状数组)

2024-06-01 19:18

本文主要是介绍URAL 1707. Hypnotoad's Secret(树状数组),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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;
}


这篇关于URAL 1707. Hypnotoad's Secret(树状数组)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1021881

相关文章

Java 字符数组转字符串的常用方法

《Java字符数组转字符串的常用方法》文章总结了在Java中将字符数组转换为字符串的几种常用方法,包括使用String构造函数、String.valueOf()方法、StringBuilder以及A... 目录1. 使用String构造函数1.1 基本转换方法1.2 注意事项2. 使用String.valu

JAVA中整型数组、字符串数组、整型数和字符串 的创建与转换的方法

《JAVA中整型数组、字符串数组、整型数和字符串的创建与转换的方法》本文介绍了Java中字符串、字符数组和整型数组的创建方法,以及它们之间的转换方法,还详细讲解了字符串中的一些常用方法,如index... 目录一、字符串、字符数组和整型数组的创建1、字符串的创建方法1.1 通过引用字符数组来创建字符串1.2

vue如何监听对象或者数组某个属性的变化详解

《vue如何监听对象或者数组某个属性的变化详解》这篇文章主要给大家介绍了关于vue如何监听对象或者数组某个属性的变化,在Vue.js中可以通过watch监听属性变化并动态修改其他属性的值,watch通... 目录前言用watch监听深度监听使用计算属性watch和计算属性的区别在vue 3中使用watchE

hdu2241(二分+合并数组)

题意:判断是否存在a+b+c = x,a,b,c分别属于集合A,B,C 如果用暴力会超时,所以这里用到了数组合并,将b,c数组合并成d,d数组存的是b,c数组元素的和,然后对d数组进行二分就可以了 代码如下(附注释): #include<iostream>#include<algorithm>#include<cstring>#include<stack>#include<que

hdu 1166 敌兵布阵(树状数组 or 线段树)

题意是求一个线段的和,在线段上可以进行加减的修改。 树状数组的模板题。 代码: #include <stdio.h>#include <string.h>const int maxn = 50000 + 1;int c[maxn];int n;int lowbit(int x){return x & -x;}void add(int x, int num){while

90、k8s之secret+configMap

一、secret配置管理 配置管理: 加密配置:保存密码,token,其他敏感信息的k8s资源 应用配置:我们需要定制化的给应用进行配置,我们需要把定制好的配置文件同步到pod当中容器 1.1、加密配置: secret: [root@master01 ~]# kubectl get secrets ##查看加密配置[root@master01 ~]# kubectl get se

ural 1297. Palindrome dp

1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unli

ural 1149. Sinus Dances dfs

1149. Sinus Dances Time limit: 1.0 second Memory limit: 64 MB Let  An = sin(1–sin(2+sin(3–sin(4+…sin( n))…) Let  Sn = (…( A 1+ n) A 2+ n–1) A 3+…+2) An+1 For given  N print  SN Input One

ural 1820. Ural Steaks 贪心

1820. Ural Steaks Time limit: 0.5 second Memory limit: 64 MB After the personal contest, happy but hungry programmers dropped into the restaurant “Ural Steaks” and ordered  n specialty steaks

ural 1017. Staircases DP

1017. Staircases Time limit: 1.0 second Memory limit: 64 MB One curious child has a set of  N little bricks (5 ≤  N ≤ 500). From these bricks he builds different staircases. Staircase consist