POJ 2155 Matrix【 二维树状数组 】
题意:给出两种操作,C是给出一个矩形的左上角和左下角的下标,把这个矩形里面的0变成1,1变成0,Q是询问某个点的值
看这篇论文讲得很清楚
http://wenku.baidu.com/view/1e51750abb68a98271fefaa8
自己看的时候,把每个点对应覆盖哪些区域画出来,再结合论文里面的,好理解一些
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include <cmath>
- #include<stack>
- #include<vector>
- #include<map>
- #include<set>
- #include<queue>
- #include<algorithm>
- using namespace std;
- typedef long long LL;
- const int INF = (<<)-;
- const int mod=;
- const int maxn=;
- int n;
- int c[maxn][maxn];
- int lowbit(int x){ return x & (-x);}
- int sum(int x,int y){
- int ret=,y1;
- while(x>){
- y1=y;
- while(y1>){
- ret+=c[x][y1];y1-=lowbit(y1);
- }
- x-=lowbit(x);
- }
- return ret;
- }
- void add(int x,int y,int d){
- int y1;
- while(x<=n){
- y1=y;
- while(y1<=n){
- c[x][y1]+=d;y1+=lowbit(y1);
- }
- x+=lowbit(x);
- }
- }
- int main(){
- int T;
- scanf("%d",&T);
- while(T--){
- int m;
- memset(c,,sizeof(c));
- scanf("%d%d%*c",&n,&m);
- while(m--){
- char ch;
- scanf("%c",&ch);
- if(ch == 'C'){
- int x1,y1,x2,y2;
- scanf("%d%d",&x1,&y1);
- scanf("%d%d%*c",&x2,&y2);
- add(x1,y1,);
- add(x1,y2+,-);
- add(x2+,y1,-);
- add(x2+,y2+,);
- }
- else {
- int l,r;
- scanf("%d%d%*c",&l,&r);
- int ans;
- ans=sum(l,r);
- printf("%d\n",ans%);
- }
- }
- if(T>=) puts("");
- }
- return ;
- }
POJ 2155 Matrix【 二维树状数组 】的更多相关文章
- POJ 2155 Matrix(二维树状数组,绝对具体)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 20599 Accepted: 7673 Descripti ...
- poj 2155 Matrix (二维树状数组)
题意:给你一个矩阵开始全是0,然后给你两种指令,第一种:C x1,y1,x2,y2 就是将左上角为x1,y1,右下角为x2,y2,的这个矩阵内的数字全部翻转,0变1,1变0 第二种:Q x1 y1,输 ...
- POJ 2155:Matrix 二维树状数组
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 21757 Accepted: 8141 Descripti ...
- [poj2155]Matrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25004 Accepted: 9261 Descripti ...
- 【poj2155】Matrix(二维树状数组区间更新+单点查询)
Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...
- POJ 2029 (二维树状数组)题解
思路: 大力出奇迹,先用二维树状数组存,然后暴力枚举 算某个矩形区域的值的示意图如下,代码在下面慢慢找... 代码: #include<cstdio> #include<map> ...
- poj----2155 Matrix(二维树状数组第二类)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16950 Accepted: 6369 Descripti ...
- poj 2155 B - Matrix 二维树状数组
#include<iostream> #include<string> #include<string.h> #include<cstdio> usin ...
- POJ2155:Matrix(二维树状数组,经典)
Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...
- Matrix 二维树状数组的第二类应用
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17976 Accepted: 6737 Descripti ...
随机推荐
- sql server 随机生成布尔值
) AS BIT) 或者 )
- Hua Wei 机试题目三---2014
一.根据对应规则进行翻译输出 描述:已知有如下的对应规则: ,则输入任意个正整数,输出经过规则翻译以后对应的结果. 例如:输入:1234:输出bcde. 题目很简单,我觉得需要注意的问题就是对于大整数 ...
- 微信小程序分享朋友圈的实现思路与解决办法
实现思路 那么既然小程序没有分享到朋友圈的api,我们怎么实现分享到朋友圈呢,下面我介绍一下实现思路. 既然没有捷径,那就走复杂一点的路线,那就是需要用户手动分享到朋友圈,问题又来了,用户手动分享的话 ...
- [转]opencv学习资料
转自:http://blog.csdn.net/poem_qianmo/article/details/20537737 1:Mat imread(const string& filename ...
- CentOS 6.5下部署日志服务器 Rsyslog+LogAnalyzer+MySQL
简介 LogAnalyzer 是一款syslog日志和其他网络事件数据的Web前端.它提供了对日志的简单浏览.搜索.基本分析和一些图表报告的功能.数据可以从数据库或一般的syslog文本文件中获取,所 ...
- jq——css类
1 addClass(classname) 添加类 <script type="text/javascript"> $("input").clic ...
- web 安全主题
- JS数组中的indexOf方法
前言 这两天在家中帮朋友做项目,项目中使用了数组的indexOf 方法,找到了一篇文章,感觉非常不错,顺便整理下以防链接丢失. 相信说到 indexOf 大家并不陌生,判断字符串是否包涵子字符串时特别 ...
- 关于fromkeys的用法
分享一个小知识点: 1. Python 中关于dict的fromkeys方法: 1. fromkeys是用于重构字典 2. 至少传一个参数,第一个参数为新建dict的key,如果第一个参数为字典,那么 ...
- java EE使用response返回中文时,出现乱码问题
response.setHeader("content-type", "text/html;charset=UTF-8");