题意:给出两种操作,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【 二维树状数组 】的更多相关文章

  1. POJ 2155 Matrix(二维树状数组,绝对具体)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20599   Accepted: 7673 Descripti ...

  2. poj 2155 Matrix (二维树状数组)

    题意:给你一个矩阵开始全是0,然后给你两种指令,第一种:C x1,y1,x2,y2 就是将左上角为x1,y1,右下角为x2,y2,的这个矩阵内的数字全部翻转,0变1,1变0 第二种:Q x1 y1,输 ...

  3. POJ 2155:Matrix 二维树状数组

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 21757   Accepted: 8141 Descripti ...

  4. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

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

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

  6. POJ 2029 (二维树状数组)题解

    思路: 大力出奇迹,先用二维树状数组存,然后暴力枚举 算某个矩形区域的值的示意图如下,代码在下面慢慢找... 代码: #include<cstdio> #include<map> ...

  7. poj----2155 Matrix(二维树状数组第二类)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16950   Accepted: 6369 Descripti ...

  8. poj 2155 B - Matrix 二维树状数组

    #include<iostream> #include<string> #include<string.h> #include<cstdio> usin ...

  9. POJ2155:Matrix(二维树状数组,经典)

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

  10. Matrix 二维树状数组的第二类应用

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17976   Accepted: 6737 Descripti ...

随机推荐

  1. Web前端必须规避的8个误区

    现在,有越来越多所谓的“教程”来帮助我们提高网站的易用性.下面收集了一些在Web开发中容易出错和被忽略的小问题,并且提供了参考的解决方案,以便于帮助Web开发者更好的完善网站. 通过避免下面这些小错误 ...

  2. Element-ui组件--pagination分页的使用

    一般在写前端页面时,经常会遇到分页这样的效果,element-ui中便有这样的插件,用vue框架使用的很方便,在此做一总结: <template> <div class=" ...

  3. 三种排序方法(c语言)

    #include "stdio.h" void main() {void read_data(int a[],int n); void write_data(int a[],int ...

  4. Activity-任务栈和启动模式

    为什么需要了解关于Activity的任务栈,其实最直接的体现就是提高用户交互友好性. 举个例子,当我们去浏览一个新闻客户端的时候,我们进入了新闻详情页,在这个页面有相隔两条的新闻标题,当我们去点击这个 ...

  5. Android自定义日历控件(继承系统控件实现)

    Android自定义日历控件(继承系统控件实现) 主要步骤 编写布局 继承LinearLayout设置子控件 设置数据 继承TextView实现有圆圈背景的TextView 添加Attribute 添 ...

  6. 学Arduino 需要做哪些准备?(引自"知乎用户:郑兴芳,DhP"的回答)

    本人非电子专业,使用Arduino完全出于兴趣,目前主要用于实验过程中的自动化操作. 一.基础准备主要是看一些入门介绍的电子文档,如Arduino_Basic.PDF.ArduinoL2.PDF .& ...

  7. 浏览器渲染HTML页面步骤

    渲染步骤:浏览器渲染页面时,表示网站资源已经请求成功(要了解查看:浏览器向服务器请求资源过程) 解析HTML以构建dom树--->构建render树--->布局render树---> ...

  8. Python 进行网络编程

    Date: 2019-06-10 Author: Sun 1. Python TCP通信实现 socket()函数 Python 中,我们用 socket()函数来创建套接字,语法格式如下: sock ...

  9. CF894E Ralph and Mushrooms_强连通分量_记忆化搜索_缩点

    Code: #include<cstdio> #include<stack> #include<cstring> using namespace std; cons ...

  10. Could not find result map java.util.HashMap

    Could not find result map java.util.HashMap 找不到结果图java.util.HashMap MyBatis 找不到返回的 'resultMap'!把resu ...