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. pytorch定义一个简单的神经网络

    刚学习pytorch,简单记录一下 """ test Funcition """ import torch from torch.autog ...

  2. hdu6435 Problem J. CSGO标程讲解以及改正标程的一个错误(本来第一个样例过不了2333) 以及 poj2926 五维曼哈顿距离模板

    比赛的时候抄poj2926的模板,但改不来啊orz #include <iostream> #include <cstdio> #include <cstring> ...

  3. Redis环境配置和命令语句

    环境配置 拷贝Redis-x64-3.2.100到本地一个目录下,解压 然后设置环境变量PATH到该目录 Redis-server.exe:Redis服务端 Redis-cli.exe:Redis客户 ...

  4. 关于Java程序流程控制的整理(已完善)

  5. Flume 在有赞大数据的实践

    https://mp.weixin.qq.com/s/gd0KMAt7z0WbrJL0RkMEtA 原创: 有赞技术 有赞coder 今天 文 | hujiahua on 大数据 一.前言 Flume ...

  6. LeetCode 617 Merge Two Binary Trees 解题报告

    题目要求 Given two binary trees and imagine that when you put one of them to cover the other, some nodes ...

  7. 第二章 深入C#数据类型

    深入C#数据类型       巧记:值(无ref)+值=不变 值(无ref)+引=变     引(有ref)+值/引=变     1.值类型和引用类型 1.引用类型 源于system.object家族 ...

  8. Linux I/O重定向

    所谓I/O重定向简单来说就是一个过程,这个过程捕捉一个文件,或者命令,程序,脚本,甚至脚本中的代码块的输出,然后把捕捉到的输出,作为输入 发送给另外一个文件,命令,程序,或者脚本.谈到I/O重定向,就 ...

  9. Examples of GoF Design Patterns in Java's core libraries

    设计模式分类 stackOverflow Structural(结构模式) Adapter:把一个接口或是类变成另外一种. java.util.Arrays#asList() javax.swing. ...

  10. 【托业】【新东方全真模拟】01~02-----P5~6

    12.precisely precise precision preciseness 114. 116. favorable adj.赞同的; 称赞的; 有利的; 讨人喜欢的; favor n.好感; ...