HDU 4456 Crowd
Crowd
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1287 Accepted Submission(s): 290
Since frequent accidents had happened last year when the citizens went out to admire the colorful lanterns, City F is planning to develop a system to calculate the degree of congestion of the intersection of two streets.
The map of City F is organized in an N×N grid (N north-south streets and N west-east street). For each intersection of streets, we define a density value for the crowd on the intersection.
Initially, the density value of every intersection is zero. As time goes by, the density values may change frequently. A set of cameras with new graphical recognition technology can calculate the density value of the intersection easily in a short time.
But the administrator of the police office is planning to develop a system to calculate the degree of congestion. For some consideration, they come up with a conception called "k-dimension congestion degree". The "k-dimension congestion degree" of intersection (x0,y0) is represented as "c(x0,y0,k)", and it can be calculated by the formula below:

Here, d(x,y) stands for the density value on intersection (x,y) and (x,y) must be in the N×N grid. The formula means that all the intersections in the range of manhattan distance k from (x0,y0) effect the k-dimension congestion degree of (x0,y0) equally, so we just simply sum them up to get the k-dimension congestion degree of (x0,y0).
The figure below shows a 7×7 grid, and it shows that if you want to get the 2-dimension congestion degree of intersection (4,2),you should sum up the density values of all marked intersections.

Each test case begins with a line with two integers N, M, meaning that the city is an N×N grid and there will be M queries or events as time goes by. (1 ≤ N ≤10 000, 1 ≤ M ≤ 80 000) Then M lines follow. Each line indicates a query or an event which is given in form of (p, x, y, z), here p = 1 or 2, 1 ≤ x ≤ N, 1 ≤ y ≤ N.
The meaning of different p is shown below.
1. p = 1 the value of d(x,y) is increased by z, here -100 ≤ z ≤ 100.
2. p = 2 query the value of c(x,y,z), here 0 ≤ z ≤ 2N-1.
Input is terminated by N=0.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
struct QU {
int x1,x2,y,id,f;
QU(int a = ,int b = ,int c = ,int d = ,int e = ) {
x1 = a;
x2 = b;
y = c;
id = d;
f = e;
}
bool operator<(const QU &t)const {
return y < t.y;
}
} Q[maxn],A[maxn],B[maxn];
LL C[maxn],ans[maxn];
void add(int i,int val) {
while(i < maxn) {
C[i] += val;
i += i&-i;
}
}
LL sum(int i,LL ret = ) {
while(i > ) {
ret += C[i];
i -= i&-i;
}
return ret;
}
void cdq(int L,int R) {
if(R <= L) return;
int mid = (L + R)>>;
cdq(L,mid);
cdq(mid+,R);
int a = ,b = ,j = ;
for(int i = L; i <= mid; ++i)
if(Q[i].id == -) A[a++] = Q[i];
for(int i = mid + ; i <= R; ++i)
if(Q[i].id != -) B[b++] = Q[i];
sort(A,A + a);
sort(B,B + b);
for(int i = ; i < b; ++i) {
for(; j < a && A[j].y <= B[i].y; ++j) add(A[j].x1,A[j].f);
ans[B[i].id] += B[i].f*sum(B[i].x2);
ans[B[i].id] -= B[i].f*sum(B[i].x1);
}
for(int i = ; i < j; ++i) add(A[i].x1,-A[i].f);
}
int main() {
int n,m,op,x,y,z,tot,ask;
while(scanf("%d",&n),n) {
scanf("%d",&m);
ask = tot = ;
memset(ans,,sizeof ans);
while(m--) {
scanf("%d%d%d%d",&op,&x,&y,&z);
if(op == ) Q[tot++] = QU(x + y,,y - x,-,z);
else {
int cx = x + y;
int cy = y - x;
int x1 = cx - z;
int x2 = cx + z;
int y1 = cy - z;
int y2 = cy + z;
Q[tot++] = QU(x1-,x2,y2,ask,);
Q[tot++] = QU(x1-,x2,y1-,ask++,-);
}
}
cdq(,tot-);
for(int i = ; i < ask; ++i)
printf("%I64d\n",ans[i]);
}
return ;
}
HDU 4456 Crowd的更多相关文章
- cdq分治(hdu 5618 Jam's problem again[陌上花开]、CQOI 2011 动态逆序对、hdu 4742 Pinball Game、hdu 4456 Crowd、[HEOI2016/TJOI2016]序列、[NOI2007]货币兑换 )
hdu 5618 Jam's problem again #include <bits/stdc++.h> #define MAXN 100010 using namespace std; ...
- 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)
BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...
- HDU 4456(二维树状数组+坐标转换)
题目链接:Problem - 4456 看别人叙述看的心烦,于是我自己画了一张图. 上图. 上代码 #include <iostream> #include <cstdio> ...
- HDU - 4456 cdq
题意:给一个矩阵,两种操作1:修改单点的权值,2:查询和某个点曼哈顿距离小于r点的权值和 题解:先旋转坐标轴,(x,y)->(x-y,x+y)然后就变成了cdq分治裸题,子矩阵和和单点修改一维时 ...
- hdu 4815 Little Tiger vs. Deep Monkey(01背包)
http://acm.hdu.edu.cn/showproblem.php?pid=4815 Description A crowd of little animals is visiting a m ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 如何更改iTunes备份地址(修改iphone ipad 备份地址) itunes文件目录修改方法 【亲测有效,附带原理说明】
前言 C盘空间有限,但是iTunes就是那么龌龊,只能把手机备份存到C盘.那么怎么才能把备份文件存到其他分区的文件夹里面呢? 当时我想先看看度娘,看看有没有现成的! 结果 nnd!! 我看了一大堆相关 ...
- 修改android系统开机动画
本文转载自:http://blog.csdn.net/u012301841/article/details/51598115 修改android系统开机动画
- 2017 Multi-University Training Contest - Team 2 &hdu 6055 Regular polygon
Regular polygon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 【POJ 2449】 Remmarguts' Date
[题目链接] http://poj.org/problem?id=2449 [算法] A*(启发式搜索) 首先,求第k短路可以用优先队列BFS实现,当T第k次入队时,就求得了第k短路,但是,这种做法的 ...
- 如何修改vos2009/vos3000的web端口?
vos 2009. VOS 3000 2120 -2138版本在这里 /usr/apache-tomcat-5.5.15/conf 编辑 server.xml 找到 <!-- Define a ...
- 【WIP】Rails devise导入与使用方法
创建: 2017/09/07 更新: 2017/10/14 标题加上[WIP] 源代码: https://github.com/plataformatec/devise 命令行内容总结 安 ...
- A Round Peg in a Ground Hole(圆与凸包)
http://poj.org/problem?id=1584 题意:判断所给的点能不能形成凸包,并判断所给的圆是否在凸包内. 改了好几天的一个题,今天才发现是输入顺序弄错了,办过的最脑残的事情..sa ...
- jFinal基于maven简单的demo
JFinal 是基于Java 语言的极速 web 开发框架,其核心设计目标是开发迅速.代码量少.学习简单.功能强大.轻量级.易扩展.Restful.在拥有Java语言所有优势的同时再拥有ruby.py ...
- struts2OGNL表达式(三)
OGNL表达式 OGNL对象试图导航语言.${user.addr.name}这种写法就叫对象试图导航.Struts框架使用OGNL作为默认的表达式语言 OGNL不仅仅可以试图导航,支持比EL表达式更加 ...
- 2018.10.9 上线发现elasticsearch写入速度超级慢,原来罪魁祸首是阿里云服务的OSS的锅
问题描述: 按照项目计划,今天上线部署日志系统(收集线上的所有日志,便于问题排查). 运维按照以前的部署过程,部署elasticsearch,部署结束之后,通过x-pack的monitor发现elas ...