POJ 2155 Matrix(二维BIT)
Matrix
【题目链接】Matrix
【题目类型】二维BIT
&题解:
bit只能单点更新,恰好,这题可以想一下就可以用单点更新解决了.
只不过最后我交上去居然T了,想了10多分钟,试了一下关同步,结果就A了,1700ms,之后又优化了一下bit数组,改成了bool型,用了位运算,结果时间是1600ms,就快了100ms,真的不知道榜上那些100ms的代码是怎么写的 = =
&代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1005;
int n,t;
bool bit[maxn][maxn];
bool Sum(int x,int y) {
bool ans=0;
for(int i=x; i>0; i-=i&-i) {
for(int j=y; j>0; j-=j&-j) {
ans^=bit[i][j];
}
}
return ans;
}
void Add(int x,int y) {
for(int i=x; i<=n; i+=i&-i) {
for(int j=y; j<=n; j+=j&-j) {
bit[i][j]^=1;
}
}
}
int main() {
freopen("e:1.in","r",stdin);
iostream::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int T; cin>>T;
while(T--) {
memset(bit,0,sizeof(bit));
cin>>n>>t;
for(int i=0; i<t; i++) {
string op;
int x1,y1,x2,y2;
cin>>op>>x1>>y1;
if(op=="Q") {
cout<<Sum(x1,y1)<<endl;
}
else {
cin>>x2>>y2;
Add(x1,y1);
Add(x2+1,y1);
Add(x1,y2+1);
Add(x2+1,y2+1);
}
}
cout<<endl;
}
return 0;
}
POJ 2155 Matrix(二维BIT)的更多相关文章
- POJ 2155 Matrix(二维树状数组,绝对具体)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 20599 Accepted: 7673 Descripti ...
- poj 2155 matrix 二维线段树 线段树套线段树
题意 一个$n*n$矩阵,初始全为0,每次翻转一个子矩阵,然后单点查找 题解 任意一种能维护二维平面的数据结构都可以 我这里写的是二维线段树,因为四分树的写法复杂度可能会退化,因此考虑用树套树实现二维 ...
- POJ 2155 Matrix (二维线段树入门,成段更新,单点查询 / 二维树状数组,区间更新,单点查询)
题意: 有一个n*n的矩阵,初始化全部为0.有2中操作: 1.给一个子矩阵,将这个子矩阵里面所有的0变成1,1变成0:2.询问某点的值 方法一:二维线段树 参考链接: http://blog.csdn ...
- poj 2155 Matrix (二维树状数组)
题意:给你一个矩阵开始全是0,然后给你两种指令,第一种:C x1,y1,x2,y2 就是将左上角为x1,y1,右下角为x2,y2,的这个矩阵内的数字全部翻转,0变1,1变0 第二种:Q x1 y1,输 ...
- poj 2155 matrix 二维线段树
题目链接 区间翻转, 单点查询, 查询操作我真是不太明白...... #include <iostream> #include <vector> #include <cs ...
- 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 Submissions: 17880 Accepted: 6709 Descripti ...
- POJ 2155 Matrix (二维线段树)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17226 Accepted: 6461 Descripti ...
随机推荐
- [No000012F]WPF(7/7) - 样式,触发器和动画
WPF Tutorial : Beginning [^] WPF Tutorial : Layout-Panels-Containers & Layout Transformation [^] ...
- React 入门实例
React 入门实例教程 一.安装 React 的安装包,可以到官网下载. $ git clone git@github.com:ruanyf/react-demos.git 如果你没安装 git, ...
- lumen
HTTP路由 基本路由 路由参数 必填参数 可选参数 正则表达式约束 命名路由 路由组 中间件 命令空间 路由前缀 基本路由 你可以在 route/web.php 文件中定义应用程序的全部路由.最基本 ...
- [daily][editer] 二进制编辑工具 hyx
用了众多之后,终于发现了一个好用的二进制编辑工具: hyx https://yx7.cc/code/ https://en.wikipedia.org/wiki/Comparison_of_hex_e ...
- xxx污水厂监控网络定点图
- 前端 HTML 常用标签 head标签相关内容 link标签
link标签 引入CSS样式文件 href="./index.css" CSS文件的路径 <!-- 引入CSS样式文件 --> <link rel="s ...
- Mac OSX上卸载Anaconda
方案一 anaconda安装程序在~/.bash_profile脚本中新添加了一行,将anaconda bin目录添加到了$PATH环境变量中.所以你只需要删除anaconda目录,但是最好也从安装脚 ...
- vue-filter
- 小程序编辑器vscode
安装中文版 1)打开vscode工具: 2)使用快捷键组合[Ctrl+Shift+p],在搜索框中输入“configure display language”,点击确定后: 3)如图所示 =>安 ...
- 多线程——实现Runnable接口实现一个多线程
实现Runnable接口实现一个多线程 Runnable接口源码: package java.lang; //Runnable接口源码只有一个run方法 public interface Runnab ...