Matrix
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 15125   Accepted: 5683

Description

Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1 <= i, j <= N).
We can change the matrix in the following way. Given a rectangle whose upper-left corner is (x1, y1) and lower-right corner is (x2, y2), we change all the elements in the rectangle by using "not" operation (if it is a '0' then change it into '1' otherwise change it into '0'). To maintain the information of the matrix, you are asked to write a program to receive and execute two kinds of instructions.
1. C x1 y1 x2 y2 (1 <= x1 <= x2 <= n, 1 <= y1 <= y2 <= n) changes the matrix by using the rectangle whose upper-left corner is (x1, y1) and lower-right corner is (x2, y2). 2. Q x y (1 <= x, y <= n) querys A[x, y].

Input

The first line of the input is an integer X (X <= 10) representing the number of test cases. The following X blocks each represents a test case.
The first line of each block contains two numbers N and T (2 <= N <= 1000, 1 <= T <= 50000) representing the size of the matrix and the number of the instructions. The following T lines each represents an instruction having the format "Q x y" or "C x1 y1 x2 y2", which has been described above.

Output

For each querying output one line, which has an integer representing A[x, y].
There is a blank line between every two continuous test cases.

Sample Input

1
2 10
C 2 1 2 2
Q 2 2
C 2 1 2 1
Q 1 1
C 1 1 2 1
C 1 2 1 2
C 1 1 2 2
Q 1 1
C 1 1 2 1
Q 2 1

Sample Output

1
0
0
1

一个二维树状数组,好像题目说错了,其实是左下角和右上角的。
 #include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
long long int a[][];
int m;
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int y,int x1,int y1)
{
int i,j;
for(i=x1;i>;i-=lowbit(i))
for(j=y1;j>;j-=lowbit(j))
a[i][j]++; for(i=x-;i>;i-=lowbit(i))
for(j=y-;j>;j-=lowbit(j))
a[i][j]++; for(i=x1;i>;i-=lowbit(i))
for(j=y-;j>;j-=lowbit(j))
a[i][j]++; for(i=x-;i>;i-=lowbit(i))
for(j=y1;j>;j-=lowbit(j))
a[i][j]++;
}
int fun(int x,int y)
{
int i,j;
int sum=;
for(i=x;i<=m;i+=lowbit(i))
for(j=y;j<=m;j+=lowbit(j))
sum+=a[i][j];
return sum%;
}
int main()
{
//freopen("int.txt","r",stdin);
int n;
int i,j;
scanf("%d",&n);
for(i=;i<n;i++)
{
memset(a,,sizeof(a));
int k;
scanf("%d%d",&m,&k);
char b;
for(j=;j<k;j++)
{
cin>>b;
int x1,x2,y1,y2;
if(b=='Q')
{
scanf("%d%d",&x1,&y1);
printf("%d\n",fun(x1,y1));
}
else
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
update(x1,y1,x2,y2);
}
}
if(i!=n-)
printf("\n");
}
}

poj2155一个二维树状数组的更多相关文章

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

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

  2. POJ2155【二维树状数组,区间修改,点查询?】【又被输入输出坑】

    这题反反复复,到现在才过. 这道题就是树状数组的逆用,用于修改区间内容,查询点的值. 如果单纯就这个奇偶数来判的话,似乎这个思路比较好理解. 看了一下国家集训队论文(囧),<关于0与1在信息学奥 ...

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

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

  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. POJ2155/LNSYOJ113 Matrix【二维树状数组+差分】【做题报告】

    这道题是一个二维树状数组,思路十分神奇,其实还是挺水的 题目描述 给定一个N∗NN∗N的矩阵AA,其中矩阵中的元素只有0或者1,其中A[i,j]A[i,j]表示矩阵的第i行和第j列(1≤i,j≤N)( ...

  6. bzoj 1452: [JSOI2009]Count (二维树状数组)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1452 思路: 对每个颜色开一个二维树状数组维护就好了 实现代码: #include<b ...

  7. 【二维树状数组】计数问题 @JSOI2009/upcexam5911

    时间限制: 1 Sec 内存限制: 128 MB 题目描述 一个n*m的方格,初始时每个格子有一个整数权值.接下来每次有2种操作: 改变一个格子的权值: 求一个子矩阵中某种特定权值出现的个数. 输入 ...

  8. BZOJ 1452 Count 【模板】二维树状数组

    对每种颜色开一个二维树状数组 #include<cstdio> #include<algorithm> using namespace std; ; ][maxn][maxn] ...

  9. [POJ2155]Matrix(二维树状数组)

    题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...

随机推荐

  1. jenkins 配置qq邮箱

  2. 【DDD】领域驱动设计精要

    本文算是<领域驱动设计>这本书的读书笔记,加上自己的一些读后感.网上有很多这本书的读书笔记,但是都是别人的,不如自己总结的理解深刻.建议大家在读这本书时结合<实现领域驱动设计> ...

  3. Maven01——简介、安装配置、入门程序、项目构建和依赖管理

    1 Maven的简介 1.1 什么是maven 是apache下的一个开源项目,是纯java开发,并且只是用来管理java项目的 Svn eclipse   maven量级 1.2 Maven好处 同 ...

  4. 【小白成长撸】--多项式求圆周率PI

    /*程序的版权和版本声明部分: *Copyright(c) 2016,电子科技大学本科生 *All rights reserved. *文件名:多项式求PI *程序作用:计算圆周率PI *作者:Amo ...

  5. SQL Server 2008 开启数据库的远程连接

     转载: 陈萌_1016----有道云笔记 SQL Server 2008默认是不允许远程连接的,如果想要在本地用SSMS连接远程服务器上的SQL Server 2008,远程连接数据库.需要做两个部 ...

  6. 入侵检测工具之RKHunter & AIDE

    一.AIDE AIDE全称为(Adevanced Intrusion Detection Environment)是一个入侵检测工具,主要用于检查文件的完整性,审计系统中的工具是否被更改过. AIDE ...

  7. Spring mvc 转发、重定向

    spring控制器最后返回一个ModelAndView(urlName),其中urNamel可以是一个视图名称,由视图解析器负责解析后将响应流写回客户端;也可以通过redirect/forward:u ...

  8. 大数的减法函数--c语言

    代码展示:   http://paste.ubuntu.com/23693598/ #include<stdio.h> #include<stdlib.h> #include& ...

  9. 201521123084 《Java程序设计》第3周学习总结

    1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识组织起来.请使用纸笔或者下面的工具画出本周学习到的知识点.截图或者拍照上传. 本周学习总结 ...

  10. 集美大学网络1413第十四次作业成绩(团队九) -- 测试与发布&博客展示(Beta版本)

    题目 团队作业9--测试与发布(Beta版本) 团队作业9成绩  团队/分值 Beta版本测试报告 Beta版本发布说明       总分  Bug类别. 数量 场景测试 测试结果 测试矩阵 出口条件 ...