whu 643 Soul Artist(二维BIT 区间更新,单点查询)
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 区间更新,单点查询)的更多相关文章
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
		HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ... 
- codevs 1081 线段树练习 2  区间更新 单点查询 无lazy
		题目描述 Description 给你N个数,有两种操作 1:给区间[a,b]的所有数都增加X 2:询问第i个数是什么? 输入描述 Input Description 第一行一个正整数n,接下来n行n ... 
- CDOJ  1059   秋实大哥与小朋友     STL(set)+离散化+BIT区间更新单点查询
		链接: A - 秋实大哥与小朋友 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu Subm ... 
- 【poj2155】Matrix(二维树状数组区间更新+单点查询)
		Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ... 
- NBOJv2 1050 Just Go(线段树/树状数组区间更新单点查询)
		Problem 1050: Just Go Time Limits: 3000 MS Memory Limits: 65536 KB 64-bit interger IO format: % ... 
- hdu1556 树状数组区间更新单点查询板子
		就是裸的区间更新: 相对于直观的线段树的区间更新,树状数组的区间更新原理不太相同:由于数组中的一个结点控制的是一块区间,当遇到更新[l,r]时,先将所有能控制到 l 的结点给更新了,这样一来就是一下子 ... 
- hdu3966 树链剖分点权模板+线段树区间更新/树状数组区间更新单点查询
		点权树的模板题,另外发现树状数组也是可以区间更新的.. 注意在对链进行操作时方向不要搞错 线段树版本 #include<bits/stdc++.h> using namespace std ... 
- HDU 5861 Road 线段树区间更新单点查询
		题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ... 
- ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】
		任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ... 
随机推荐
- iOS开发尺寸记录
			https://kapeli.com/cheat_sheets/iOS_Design.docset/Contents/Resources/Documents/index https://help.ap ... 
- debian设置软件源为阿里云
			首先编辑sources.list这个文件 sudo vim /etc/apt/sources.list 把sources.list文件内容替换成如下 deb http://mirrors.aliyun ... 
- flannel
			Docker跨主机容器间网络通信实现的工具有Pipework.Flannel.Weave.Open vSwitch(虚拟交换机).Calico实现跨主机容器间的通信.其中Pipework.Weave. ... 
- Coding 小技巧
			</pre>//格式化字符串的传递<p></p><p>#define FSKILL_LOG(format ,...) DREAMLAND_RUNI ... 
- 使用TidCookieManager得到cookie
			1.拖入TIdHTTP控件,HandleRedirect设为True,否则可能会出现HTTP 307错误. 2.主要的设置在Request里. 2.1 userAgent应该改为Mozilla/4.0 ... 
- LeetCode 812 Largest Triangle Area 解题报告
			题目要求 You have a list of points in the plane. Return the area of the largest triangle that can be for ... 
- SQL join的介绍
			学员表 SELECT * FROM tb_address; SELECT * FROM tb_student 1.JOIN关联两个表数据,将匹配数据展示,数据无匹配值则不展示 注释:INNER JOI ... 
- 预备作业2 :学习基础和C语言基础调查
			剑网三毒经pk心得: 看完标题的你真的没有进错,这里是博客园. 想到写这篇文章的原因一部分是自己的确没啥技能比超过90%以上的人还好,还有一部分是受到了作业提示的指引...... 如果你有类似的技能获 ... 
- js面向对象、创建对象的工厂模式、构造函数模式、原型链模式
			JS面向对象编程(转载) 什么是面向对象编程(OOP)?用对象的思想去写代码,就是面向对象编程. 面向对象编程的特点 抽象:抓住核心问题 封装:只能通过对象来访问方法 继承:从已有对象上继承出新的对象 ... 
- Jenkins send build artifacts over ssh配置
			配置jenkins远程部署的时候遇到的配置问题: 首先在系统设置-系统设置-Publish over SSH-SSH Server中配置服务器信息 配置完成后可以点击Test Configuratio ... 
