Matrix

Time Limit: 3000 MS Memory Limit: 65536 KB

64-bit integer IO format: %I64d , %I64u Java class name: Main

[Submit] [Status] [Discuss]

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 <stdio.h>
#include <string.h> using namespace std;
#define max 1005
int c[max][max];
int n; int lowbit(int x)
{
return x&-x;
} void update(int x,int y,int val)
{
for(int i=x; i<=n; i+=lowbit(i))
{
for(int j=y; j<=n; j+=lowbit(j))
{
c[i][j]+=val;
}
}
} int get_sum(int x,int y)
{
int s=;
for(int i=x; i>; i-=lowbit(i))
{
for(int j=y; j>; j-=lowbit(j))
{
s+=c[i][j];
}
}
return s;
} int main()
{
/// freopen("in.txt","r",stdin);
///freopen("out.txt","w",stdout);
int cc,t,x1,x2,y1,y2,a,b;
char ch;
scanf("%d",&cc);
for(int i=;i<=cc;i++)
{
memset(c,,sizeof(c));
scanf("%d%d",&n,&t);
getchar();
for(int j=;j<t;j++) ///下标不可以从0开始 会死循环
{
scanf("%c",&ch);
if(ch=='C')
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
getchar();
update(x1,y1,);
update(x1,y2+,);
update(x2+,y1,);
update(x2+,y2+,);
}
else
{
scanf("%d%d",&a,&b);
getchar();
printf("%d\n",get_sum(a,b)%);
}
}
printf("\n");
}
return ;
}

* 矩阵的00在左上角

http://blog.csdn.net/zxy_snow/article/details/6264135   图示

poj 2155 区间更新 单点查询的更多相关文章

  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. HDU 5861 Road 线段树区间更新单点查询

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...

  7. ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】

    任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...

  8. hdu1556 树状数组区间更新单点查询板子

    就是裸的区间更新: 相对于直观的线段树的区间更新,树状数组的区间更新原理不太相同:由于数组中的一个结点控制的是一块区间,当遇到更新[l,r]时,先将所有能控制到 l 的结点给更新了,这样一来就是一下子 ...

  9. hdu3966 树链剖分点权模板+线段树区间更新/树状数组区间更新单点查询

    点权树的模板题,另外发现树状数组也是可以区间更新的.. 注意在对链进行操作时方向不要搞错 线段树版本 #include<bits/stdc++.h> using namespace std ...

随机推荐

  1. Codeforces 787D. Legacy 线段树建模+最短路

    D. Legacy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  2. 性能监控工具——Cacti安装文档

    一.Cacti安装说明 1.安装说明 一般性的安装说明,详细的操作系统具体的安装说明可用于Linux. 2.服务器安装要求 RRDTool 1.2.x或更高版本 MySQL 4.1.x或5.x更高版本 ...

  3. UI设计工资有多高?怎么快速拿高薪?

    1.UI设计工资有多高? 有人不服UI设计待遇薪资高,那么下面就来看下一线城市的最新UI设计平均薪资待遇,大家也可以打开各招聘网站查询各行业平均薪资情况,一个行业的薪资高不高行业市场决定. 待遇较高说 ...

  4. UI设计师经常去的五个网站

    1.站酷 站酷(ZCOOL),中国人气设计师互动平台.深耕设计领域十年,站酷聚集了470万优秀设计师.摄影师.插画师.艺术家.创意人,设计创意群体中具有较高的影响力与号召力.   2.花瓣 花瓣网, ...

  5. Spring ApplicationContext(六)BeanPostProcessor

    Spring ApplicationContext(六)BeanPostProcessor 产生回顾一下 ApplicationContext 初始化的几个步骤:第一步是刷新环境变量:第二步是刷新 b ...

  6. Python3实战系列之三(获取印度售后数据项目)

    问题:续接上一篇.说干咱就干呀,勤勤恳恳写程序呀! 目标:实现第一个python程序的“Hello world!” 解决方案:新建一个项目Test,创建一个Test.py文件.在文件中实现打印出“He ...

  7. DNA计算机及DNA存储

    傅里叶变换到量子水平,可编程元素到原子分子核能,都可以极大的改变有机体(高级有机体都是有寿命的,例如人类),如果可以出现机械体,核能提供能量:并结合类似高级生物大脑的有机体大脑,不断学习进化,甚至优化 ...

  8. Ajax在jQuery中的应用 (4)向jsp提交表单数据

    ajax技术带给我们的是良好的用户体验,同时,使用jquery可以简化开发,提高工作效率. 下面就介绍一下大致的开发步骤. 工具/原料 本文中使用的是 jquery-1.3.2.min.js 方法/步 ...

  9. go基础知识之变量,类型,常量,函数

    3 变量 变量是什么 变量指定了某存储单元(Memory Location)的名称,该存储单元会存储特定类型的值.在 Go 中,有多种语法用于声明变量. 声明单个变量 var name type 是声 ...

  10. 43.Charles抓包(iOS的http/https请求)

    Charles安装 HTTP抓包 HTTPS抓包     1. Charles安装 官网下载安装Charles: https://www.charlesproxy.com/download/ 2. H ...