poj 2155 matrix 二维线段树
区间翻转, 单点查询, 查询操作我真是不太明白......
#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 二维线段树的更多相关文章
- poj 2155 matrix 二维线段树 线段树套线段树
题意 一个$n*n$矩阵,初始全为0,每次翻转一个子矩阵,然后单点查找 题解 任意一种能维护二维平面的数据结构都可以 我这里写的是二维线段树,因为四分树的写法复杂度可能会退化,因此考虑用树套树实现二维 ...
- POJ 2155 Matrix (二维线段树入门,成段更新,单点查询 / 二维树状数组,区间更新,单点查询)
题意: 有一个n*n的矩阵,初始化全部为0.有2中操作: 1.给一个子矩阵,将这个子矩阵里面所有的0变成1,1变成0:2.询问某点的值 方法一:二维线段树 参考链接: http://blog.csdn ...
- POJ2155 Matrix二维线段树经典题
题目链接 二维树状数组 #include<iostream> #include<math.h> #include<algorithm> #include<st ...
- POJ2155 Matrix 二维线段树
关键词:线段树 二维线段树维护一个 维护一个X线段的线段树,每个X节点维护一个 维护一个Y线段的线段树. 注意,以下代码没有PushDownX.因为如果要这么做,PushDownX时,由于当前X节点的 ...
- POJ 2155 Matrix(二维树状数组,绝对具体)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 20599 Accepted: 7673 Descripti ...
- poj 2155 Matrix (二维树状数组)
题意:给你一个矩阵开始全是0,然后给你两种指令,第一种:C x1,y1,x2,y2 就是将左上角为x1,y1,右下角为x2,y2,的这个矩阵内的数字全部翻转,0变1,1变0 第二种:Q x1 y1,输 ...
- POJ 2155 Matrix(二维BIT)
Matrix [题目链接]Matrix [题目类型]二维BIT &题解: bit只能单点更新,恰好,这题可以想一下就可以用单点更新解决了. 只不过最后我交上去居然T了,想了10多分钟,试了一下 ...
- POJ 2019 Cornfields 二维线段树的初始化与最值查询
模板到不行.. 连更新都没有.. .存个模板. 理解留到小结的时候再写. #include <algorithm> #include <iostream> #include & ...
- poj 2155:Matrix(二维线段树,矩阵取反,好题)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17880 Accepted: 6709 Descripti ...
随机推荐
- bootstrap-js(5)工具提示tooltip
实例 当您想要描述一个链接的时候,工具提示(Tooltip)就显得非常有用.工具提示(Tooltip)插件是受 Jason Frame 写的 jQuery.tipsy 的启发.工具提示(Tooltip ...
- android的二进制和十六进制的相互转换工具类(一):
二进制和十六进制的相互转换工具类: package com.gzcivil.utils; public class BinStr { /** * 将二进制转换成16进制 * @param buf * ...
- C#之多线程编程
一.进程与线程 进程(Process)是对一段静态指令序列(程序)的动态执行过程,是系统进行资源分配和调度的一个基本单位.与进程相关的信息包括进程的用户标识,正在执行的已经编译好的程序,进程程序和数据 ...
- http keepalive and tcpkeepalive
http keepalive 减少tcp 连接 (三次握手的消耗) tcp keepalive 检测死链接的 session 在tcp连接中, src_ip + src_port + dest_ip ...
- 图片压缩上传 Android
图片压缩的话 想保持 图像清晰度,但是又想保持图片的大小在100k左右. 同时的话又不想自己写那些压缩的代码的话.那你就找对地方了. 提供一个思路. 先读取你的文件,然后读到bitmap里面进行尺寸裁 ...
- IE6下不能定义1px高度的容器和IE6 双边距
(1)触发的条件---定义一个div,将容器的高度设置成1px (2) 编码得到的结果---在IE6浏览器中,容器的高度不是1px 而是18px (3)出现问题的原因---是因为IE6浏 ...
- project euler 48 Self powers 解决乘法爆long long
题目链接 求 $ 1^1+2^2+\cdots + 1000^{1000} $ %1e10 的结果. 唯一的坑点是会爆longlong, 所以用特殊的乘法. #include <iostream ...
- 7816的报文结构——APDU
命令APDU 包括头和主体(这可以在上面的图中看到).头包括CLA,INS,P1 和P2 域.同T0 协议一样,CLA 和INS 说明了应用的分类和指令.P1 和P2 用来详细说明具体指令,并由每一条 ...
- delphi写的整合汇编与api的简单的窗口程序
program Project1; { Types and Structures Definition }type WNDCLASSEX = packed record cbSize: Lon ...
- SDN 编程语言 p4(SDN programming language P4)
行业趋势,SND是未来. P4 是未来. SDN is inevitably, and P4 is inevitably. P4 = Programming Protocol-Independent ...