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. 静态方法中只允许访问静态数据,那么,如何在静态方法中访问类的实例成员(即没有附加static关键字的字段或方法)?

    package test.two; public class jingtaihanshu { int x = 3; static int  y = 4; public static void Meth ...

  2. 配置llama实现impala on yarn-验证未通过,仅以此文作为参考

    以下内容采自网络,目前验证未通过,仅以此作为参考: 简介:早期的Impala版本中,为了使用Impala,我们通常会在以Client/Server的结构在各个集群节点启动impala-server.i ...

  3. en-zh(社会问题)social problems

    The world's richest man, Amazon founder Jeff Bezos, and his wife MacKenzie have agreed a record-brea ...

  4. 理解HTTP协议(转载)

    一.HTTP协议的演进 HTTP(HyperText Transfer Protocol)协议是基于TCP的应用层协议,它不关心数据传输的细节,主要是用来规定客户端和服务端的数据传输格式,最初是用来向 ...

  5. [ovs] ovs开启日志debug

    如题 [root@vrouter1 ~]# ovs-appctl vlog/set netdev:file:dbg [root@vrouter1 ~]# ovs-appctl vlog/set net ...

  6. Flink - Scheduler

    Job资源分配的过程, 在submitJob中,会生成ExecutionGraph 最终调用到, executionGraph.scheduleForExecution(scheduler) 接着,E ...

  7. 转:SAX解析的characters方法被多次调用

    原文地址:https://blog.csdn.net/liuxiaoddd/article/details/28885177 android SAX解析的characters方法被多次调用 同理 试用 ...

  8. elasticsearch更新doc文档

    在elasticsearch-head中: http://localhost:9200/my_index/products/2/ _update { "script" : { &q ...

  9. eclipse debug调试时老是被URLClassLoader这个类拦截到,不能进入到要调试的类里面去

    在使用eclipse进行试的时候,一直进入到URLClassLoader,而不能正常的进入断点,后来经过查资料,解决方法如下: 上面是百度给出的答案,我把图贴在这里,以便以后其他组的朋友遇到这个问题的 ...

  10. java执行字符串数学表达式【记录】

    https://stackoverflow.com/questions/3422673/evaluating-a-math-expression-given-in-string-form 1. goo ...