Soul Artis

【题目链接】Soul Artis

【题目类型】二维BIT

&题解:

二维区间更新和一维相比,要容斥一下,更新一块区间就是更新4个点.

还有这个我先是写了2*n2logn的算法,结果t了,想了想优化了一下,变成了n2logn,就A了,终于知道了常数的重要性 0.0

&代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
const int maxn = 4e3 + 7;
int bit[maxn][maxn];
int Sum(int x, int y) {
int ans = 0;
for (int i = x; i > 0; i -= i&-i) {
for (int j = y; j > 0; j -= j&-j) {
ans += bit[i][j];
}
}
return ans;
}
void Add(int x, int y, int z) {
for (int i = x; i < maxn; i += i&-i) {
for (int j = y; j < maxn; j += j&-j) {
bit[i][j] += z;
}
}
}
void Update(int x1, int y1, int x2, int y2, int z) {
Add(x1, y1, z);
Add(x2 + 1, y1, -z);
Add(x1, y2 + 1, -z);
Add(x2 + 1, y2 + 1, z);
}
int n,m,q;
int main() {
freopen("E:1.in", "r", stdin);
iostream::sync_with_stdio(false),cin.tie(0),cout.tie(0);
while(cin>>n>>m>>q) {
memset(bit,0,sizeof(bit));
int x,y,r;
for(int i=0; i<q; i++) {
cin>>x>>y>>r;
Update(x-r-y+2000,x-r+y,x+r-y+2000,x+r+y,1);
}
int ma=0,te=0,num=0;
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
int d=Sum(i-j+2000,i+j);
ma=max(ma,d);
if(ma!=te) {
num=0;
te=ma;
}
if(d==ma) {
num++;
}
}
}
cout<<ma<<" "<<num<<endl;
}
return 0;
}

whu 643 Soul Artist(二维BIT 区间更新,单点查询)的更多相关文章

  1. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  2. codevs 1081 线段树练习 2 区间更新 单点查询 无lazy

    题目描述 Description 给你N个数,有两种操作 1:给区间[a,b]的所有数都增加X 2:询问第i个数是什么? 输入描述 Input Description 第一行一个正整数n,接下来n行n ...

  3. CDOJ 1059 秋实大哥与小朋友 STL(set)+离散化+BIT区间更新单点查询

    链接: A - 秋实大哥与小朋友 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%lld & %llu Subm ...

  4. 【poj2155】Matrix(二维树状数组区间更新+单点查询)

    Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...

  5. NBOJv2 1050 Just Go(线段树/树状数组区间更新单点查询)

    Problem 1050: Just Go Time Limits:  3000 MS   Memory Limits:  65536 KB 64-bit interger IO format:  % ...

  6. hdu1556 树状数组区间更新单点查询板子

    就是裸的区间更新: 相对于直观的线段树的区间更新,树状数组的区间更新原理不太相同:由于数组中的一个结点控制的是一块区间,当遇到更新[l,r]时,先将所有能控制到 l 的结点给更新了,这样一来就是一下子 ...

  7. hdu3966 树链剖分点权模板+线段树区间更新/树状数组区间更新单点查询

    点权树的模板题,另外发现树状数组也是可以区间更新的.. 注意在对链进行操作时方向不要搞错 线段树版本 #include<bits/stdc++.h> using namespace std ...

  8. HDU 5861 Road 线段树区间更新单点查询

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...

  9. ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】

    任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...

随机推荐

  1. [No000012F]WPF(7/7) - 样式,触发器和动画

    WPF Tutorial : Beginning [^] WPF Tutorial : Layout-Panels-Containers & Layout Transformation [^] ...

  2. 写一个表达式检查所给的整数是否它第三个数字(从右向左)是7。示例:1732 -> true。

    在学习C#基础部分(课件来源:http://www.xuepub.com/52.html),遇到这么一个题目,前段时间面试遇到一个"车牌限行的问题",我就在想如何取末尾数值的问题. ...

  3. Adobe Flex初记

    公司项目要用Flex,之前没有接触过,菜鸟只好白手起家,把项目拉下来的同时配置下Flex的环境,以下是一篇参考: http://blog.sina.com.cn/s/blog_4c4a24db0100 ...

  4. DbGridEh 一个单元格的值改变时另一单元格的值随之改变

    你可以为每个字段设置OnSetText事件,这样在输入完后回车会移动时就会触发,或者在adoquery的beforepost中或afterpost中都可以grid也提供了一些事件,也可以在某些条件下做 ...

  5. day5_函数_文件读写_用一个函数来满足文件的读或者写_应用默认参数

    import json def op_file_tojson(filename,dic=None): #默认值参数,根据是否传dic字典来判断读还是写 if dic: #如果dic传了值,不是空的,则 ...

  6. 【PyQt5-Qt Designer】QProgressBar() 进度条

    QProgressBar() 进度条 QProgressBar简介 QProgressBar小部件提供了一个水平或垂直的进度条. 进度条用于向用户指示操作的进度,并向他们保证应用程序仍在运行. 进度条 ...

  7. ubuntu上解压目录里的文件到指定文件夹

    去除目录结构加上 --strip-components N 如: 压缩文件eg.tar 中文件信息为 src/src/src/eg.txt 运行 tar -xvf eg.tar --strip-com ...

  8. gitlab数据库

    event表中action对应操作: 1 - 新建项目 5 - push 8 - 在某项目中赋予某人权限 9 - 在某项目中取消某人权限

  9. SQL专家云监控

    SQL专家云监控:http://www.zhuancloud.com/Index.html

  10. AlertWindowManager 弹出提示窗口使用帮助(上)

    LookAndFeel(界面外观): NativeStyle:本地化界面为真实用系统内置外观 SkinName:本地化界面(NativeStyle:)设置为假可使用皮肤外观 OptionAnimate ...