Matrix PKU 2155
我们可以通过以下方式更改矩阵。给定一个左上角为(x1,y1)且右下角为(x2,y2)的矩形,我们使用“not”操作更改矩形中的所有元素(如果是'0'则更改它变为'1'否则将其变为'0')。要维护矩阵的信息,系统会要求您编写程序以接收和执行两种指令。
1. C x1 y1 x2 y2(1 <= x1 <= x2 <= n,1 <= y1 <= y2 <= n)通过使用左上角为(x1,y1)和更低的矩形来改变矩阵 - 右角是(x2,y2)。
2. Q xy(1 <= x,
2 10
C 2 1 2 2
问2 2
C 2 1 2 1
问1 1
C 1 1 2 1
C 1 2 1 2
C 1 1 2 2
问1 1
C 1 1 2 1
问题2 1
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int N;
int c[][]; int lowbit(int i)
{
return i&-i;
}
void update(int x,int y,int v)
{
for(int i=x;i<=N;i+=lowbit(i))
for(int j=y;j<=N;j+=lowbit(j))
c[i][j]+=v;
}
int sum(int x,int y)
{
int ans=;
for(int i=x;i>;i-=lowbit(i))
for(int j=y;j>;j-=lowbit(j))
ans+=c[i][j];
return ans;
}
int main()
{
int cas,q;
scanf("%d",&cas);
int first=;
for(int i=;i<=cas;i++)
{
if(i!=)printf("\n");
scanf("%d%d",&N,&q);
memset(c,,sizeof(c));
char s[];
int x1,x2,y1,y2;
while(q--)
{
scanf("%s",s);
if(s[]=='C')
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
update(x1,y1,);
update(x2+,y1,-);
update(x1,y2+,-);
update(x2+,y2+,);
}
else if(s[]=='Q')
{
scanf("%d%d",&x1,&y1);
printf("%d\n",sum(x1,y1)%);
}
}
}
return ;
}
Matrix PKU 2155的更多相关文章
- PKU 2155 Matrix(裸二维树状数组)
题目大意:原题链接 题意很简单,就不赘诉了. 解题思路: 使用二维树状数组,很裸的题. 二维的写起来也很方便,两重循环. Add(int x,int y,int val)表示(x,y)-(n,n)矩形 ...
- HDU 2155 Matrix
Matrix Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 215 ...
- POJ 2155 Matrix (D区段树)
http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 1 ...
- POJ poj 2155 Matrix
题目链接[http://poj.org/problem?id=2155] /* poj 2155 Matrix 题意:矩阵加减,单点求和 二维线段树,矩阵加减,单点求和. */ using names ...
- POJ 2155 Matrix【二维树状数组+YY(区间计数)】
题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...
- POJ 2155 Matrix
二维树状数组.... Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...
- poj 2155:Matrix(二维线段树,矩阵取反,好题)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17880 Accepted: 6709 Descripti ...
- POJ 2155 Matrix (二维线段树)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17226 Accepted: 6461 Descripti ...
- POJ 2155 Matrix (二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17224 Accepted: 6460 Descripti ...
随机推荐
- 拿webshell权限方法(一)
概念 Webshell就是以asp,php,jsp或cgi等网页文件形式存在的一种命令执行环境,也可以将其称为一种网页后门. Access数据库拿webshell 首先看是否能找到网站漏洞进行网站的后 ...
- Nginx Server 配置
http { include mime.types; // 主模块:实现对配置文件包含的文件设定,可以减少主配置文件的复杂度: default_type application/octet-strea ...
- 第18月第22天 机器学习first
1.网易公开课 机器学习 http://open.163.com/special/opencourse/machinelearning.html https://github.com/search ...
- [HEOI2015]定价 (贪心)
分类讨论大法好! \(solution:\) 先说一下我对这个题目的态度: 首先这一题是贪心,这个十分明显,看了一眼其他题解都是十分优秀的贪心,可是大家都没有想过吗:你们贪心都是在区间\([l,r]\ ...
- 后端python基础
- 【文件】使用jacob将word转换成pdf格式
使用jacob将word转换成pdf格式 1.需要安装word2007或以上版本,若安装07版本学确保该版本已安装2downbank0204MicrosoftSaveasPDF_ XPS,否则安装 ...
- Android如何降低service被杀死概率
http://www.jianshu.com/p/06a1a434e057 http://www.cnblogs.com/ylligang/articles/2665181.html Android应 ...
- 阿里云apache服务器外网无法访问(配置安全组,添加80服务)
CentOS的系统 ,已经安装好了 apache php mysql 常规排错过程(ps:没耐心的童鞋请直接看最后一步,学习在阿里云控制台配置 安全组,允许 http服务) 第一步:检查apache ...
- POI导出Excel(xls、xlsx均可以,也支持图片)——(三)
Jar包
- GSON中Java对象与JSON互相转换——(一)
json的转换插件是通过java的一些工具,直接将java对象或集合转换成json字符串. 常用的json转换工具有如下几种: 1)jsonlib 2)Gson:google 3)fastjson:阿 ...