hdu 4533(树状数组)
来源:互联网 发布:艾克里里淘宝店号码 编辑:程序博客网 时间:2024/06/07 02:48
题意:给出n个矩形的左下角和右上角坐标,问矩形(0,0),(ti,ti)内矩形面积是多少,重叠也算。
题解:参照http://blog.csdn.net/shiqi_614/article/details/8869676这里的题解,把所有矩形关于t的重叠面积计算式中的系数用树状数组维护,很机智。
#include <stdio.h>#include <string.h>#include <iostream>#define ll long longusing namespace std;const int N = 200005;int n, q;ll S[3][N], x1, y1, x2, y2;int lowbit(int x) { return x & (-x); }void modify(int st, int en, ll v, int flag) { for (int i = st; i < N; i += lowbit(i)) S[flag][i] += v; for (int i = en + 1; i < N; i += lowbit(i)) S[flag][i] -= v;}ll query(int x, int flag) { ll ret = 0; for (int i = x; i > 0; i -= lowbit(i)) ret += S[flag][i]; return ret;}int main() { int t; scanf("%d", &t); while (t--) { memset(S, 0, sizeof(S)); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2); ll temp1 = max(x1, y1), temp2 = min(x2, y2); if (temp1 < temp2) { modify(temp1, temp2, 1, 0); modify(temp1, temp2, -x1 - y1, 1); modify(temp1, temp2, x1 * y1, 2); } if (y2 > x2) { temp1 = max(x2, y1) + 1; modify(temp1, y2, x2 - x1, 1); modify(temp1, y2, x1 * y1 - x2 * y1, 2); } if (x2 > y2) { temp1 = max(y2, x1) + 1; modify(temp1, x2, y2 - y1, 1); modify(temp1, x2, x1 * y1 - x1 * y2, 2); } modify(max(x2, y2) + 1, N, (y2 - y1) * (x2 - x1), 2); } scanf("%d", &q); while (q--) { ll tt; scanf("%lld", &tt); printf("%lld\n", tt * tt * query(tt, 0) + tt * query(tt, 1) + query(tt, 2)); } } return 0;}
0 0
- hdu 4533(树状数组)
- HDU 1394 树状数组
- 树状数组 hdu
- hdu 1166 树状数组
- HDU 2838 树状数组
- hdu 2492【树状数组】
- hdu 3015【树状数组】
- hdu 3874 树状数组
- hdu 3874(树状数组)
- hdu 3890 树状数组
- 【树状数组】hdu 2852
- 【树状数组】hdu 4000
- HDU 4046 树状数组
- hdu 1166(树状数组)
- HDU-3887-树状数组
- hdu 4358树状数组
- hdu 3333 树状数组
- hdu 4046 树状数组
- BZOJ1053
- Leetcode -- Add Binary
- 黑马程序员----Java中的IO流学习笔记1
- 如何在C++类中安全地使用多线程中的处理函数
- passport登陆的实现--跨域共享cookie和跨域共享session
- hdu 4533(树状数组)
- 黑马程序员--说好了的反射!
- Java修饰符关键词大全
- shell-字符截取命令sed
- InterlockedIncrement内部是如何实现的?
- 黑马程序员—IOS加强视频—分类
- 条件覆盖,路径覆盖,语句覆盖,分支覆盖解释
- 创建虚拟机生成虚拟机全程日志打印输出流程详解(openstack开发必备)
- Web开发者不容错过的10个HTML5工具