题目链接

区间翻转, 单点查询, 查询操作我真是不太明白......

     #include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = ;
int sum[maxn<<][maxn<<], n, ans;
void pushUp(int pos, int rt) {
sum[pos][rt] = sum[pos][rt<<]+sum[pos][rt<<|];
}
void sub_update(int pos, int L, int R, int l, int r, int rt) {
if(L<=l&&R>=r) {
sum[pos][rt]^=;
return ;
}
int m = l+r>>;
if(L<=m)
sub_update(pos, L, R, lson);
if(R>m)
sub_update(pos, L, R, rson);
}
void update(int LX, int RX, int LY, int RY, int l, int r, int rt) {
if(LX<=l&&RX>=r) {
sub_update(rt, LY, RY, , n, );
return ;
}
int m = l+r>>;
if(LX<=m)
update(LX, RX, LY, RY, lson);
if(RX>m)
update(LX, RX, LY, RY, rson);
}
void sub_query(int pos, int p, int l, int r, int rt) {
ans ^= sum[pos][rt];
if(l == r)
return ;
int m = l+r>>;
if(p<=m)
return sub_query(pos, p, lson);
else
return sub_query(pos, p, rson);
}
void query(int x, int y, int l, int r, int rt) {
sub_query(rt, y, , n, );
if(l == r)
return ;
int m = l+r>>;
if(x<=m)
return query(x, y, lson);
else
return query(x, y, rson);
}
int main()
{
int t, q, lx, rx, ly, ry;
cin>>t;
char c[];
while(t--) {
mem(sum);
scanf("%d%d", &n, &q);
while(q--) {
scanf("%s", c);
if(c[] == 'C') {
scanf("%d%d%d%d", &lx, &ly, &rx, &ry);
update(lx, rx, ly, ry, , n, );
} else {
scanf("%d%d", &lx, &ly);
ans = ;
query(lx, ly, , n, );
printf("%d\n", ans);
}
}
if(t)
puts("");
}
}

poj 2155 matrix 二维线段树的更多相关文章

  1. poj 2155 matrix 二维线段树 线段树套线段树

    题意 一个$n*n$矩阵,初始全为0,每次翻转一个子矩阵,然后单点查找 题解 任意一种能维护二维平面的数据结构都可以 我这里写的是二维线段树,因为四分树的写法复杂度可能会退化,因此考虑用树套树实现二维 ...

  2. POJ 2155 Matrix (二维线段树入门,成段更新,单点查询 / 二维树状数组,区间更新,单点查询)

    题意: 有一个n*n的矩阵,初始化全部为0.有2中操作: 1.给一个子矩阵,将这个子矩阵里面所有的0变成1,1变成0:2.询问某点的值 方法一:二维线段树 参考链接: http://blog.csdn ...

  3. POJ2155 Matrix二维线段树经典题

    题目链接 二维树状数组 #include<iostream> #include<math.h> #include<algorithm> #include<st ...

  4. POJ2155 Matrix 二维线段树

    关键词:线段树 二维线段树维护一个 维护一个X线段的线段树,每个X节点维护一个 维护一个Y线段的线段树. 注意,以下代码没有PushDownX.因为如果要这么做,PushDownX时,由于当前X节点的 ...

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

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

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

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

  7. POJ 2155 Matrix(二维BIT)

    Matrix [题目链接]Matrix [题目类型]二维BIT &题解: bit只能单点更新,恰好,这题可以想一下就可以用单点更新解决了. 只不过最后我交上去居然T了,想了10多分钟,试了一下 ...

  8. POJ 2019 Cornfields 二维线段树的初始化与最值查询

    模板到不行.. 连更新都没有.. .存个模板. 理解留到小结的时候再写. #include <algorithm> #include <iostream> #include & ...

  9. poj 2155:Matrix(二维线段树,矩阵取反,好题)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17880   Accepted: 6709 Descripti ...

随机推荐

  1. HBASE学习笔记--shell

    Hbase shell 启动 下载安装hbase client包,填写相关配置后进入,配置相关说明可以参见配置篇 指令:./bin/hbase shell 状态及配置信息查询 查询服务器状态 stat ...

  2. java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=Aict/listPagedAict.action

    原因:请求的URL地址不完整,没有找到host. 排查解决:发现HTTP请求的URL少加了项目名,导致URL地址不完整.

  3. User cannot be resolved to a type

    出现 User cannot be resolved to a type 不知道具体问题出在哪里但是我经过将全路径输入并保存后错误消失 将User选上,然后点击保存就可以了! 最后我发现错误消失了!

  4. 已经包含了#include <atlcom.h> #include <comutil.h>还是报错

    在WTL工程的.h中 #include <atlbase.h>#include <atlcom.h>#include <atlcomcli.h>#include & ...

  5. [置顶] woff格式字体怎么打开和编辑?

    如题! woff百度百科:http://baike.baidu.com/link?url=toS7yqpN9VlEcO2GOEp5JEA9-TeaZgIdVqTOv7iHshsNvk-V8HtxEY0 ...

  6. Android DatePicker和TimePicker

    监测日期改变的监听器:      OnDateChangedListener和OnTimeChangedListener()           当用户改变Datepicker里的年.月.日时,将触发 ...

  7. css复合属性的写法

    # 复合属性也称为 "shortcut" property (快捷属性),它作用是为了简化代码,提高页面运行的效率. # 下面的内容会介绍 2 个比较常用的复合属性 "f ...

  8. php composer包管理工具

    一 . 包管理工具 你在Centos上装工具的时候直接yum -y install xx 比你去rpm -ivh xx.rpm 是不是爽很多呢? composer 就是安装php 代码的一个类似工具. ...

  9. OC中NSArray的使用

    不可变数组类容器类,管理一组对象类型的数据.   元素是有序的,索引值从0开始  数组中存储的元素必须是对象,类型任意.   创建数组对象,使⽤用实例初始化或便利构造器.获取元素个数.根据索引值获取对 ...

  10. cad2007 钢筋符号显示为问号

    如题:cad2007 钢筋符号显示为问号 解决办法:下载Tssdeng,解压(Tssdeng.rar) 把下载到的cad大字体Tssdeng.shx文件放到autoCAD2007安装目录C:\Prog ...