poj 2155(未完成)
线段树套线段树模板题
链接:http://poj.org/problem?id=2155
题解:
代码:
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
char c;
#define maxn 1111
#define mid (p[x].h+p[x].t)/2
struct xds
{
int h,t;
struct re
{
int h,t,x,rev;
}p[maxn*];
void down(int x)
{
if (!p[x].rev) return;
if (p[x].h!=p[x].t)
{
p[x*].rev^=; p[x*+].rev^=;
} else
{
p[x].x^=;
}
p[x].rev=;
}
void build2(int x,int h,int t)
{
p[x].h=h; p[x].t=t; p[x].x=p[x].rev=;
if (h==t) return;
build2(x*,h,mid); build2(x*+,mid+,t);
}
void change2(int x,int h,int t)
{
down(x);
if (p[x].h>t||p[x].t<h) return;
if (h<=p[x].h&&p[x].t<=t)
{
p[x].rev^=; down(x); return;
}
change2(x*,h,t); change2(x*+,h,t);
}
int query2(int x,int goal)
{
down(x);
if (p[x].h==p[x].t) return(p[x].x);
if (goal>mid) return(query2(x*+,goal));
else return(query2(x*,goal));
}
}p[maxn*];
void build1(int x,int h,int t,int m)
{
p[x].h=h; p[x].t=t;
p[x].build2(,,m);
if (h==t) return;
build1(x*,h,mid,m); build1(x*+,mid+,t,m);
}
void change1(int x,int x1,int x2,int y1,int y2)
{
if (p[x].h>x2||p[x].t<x1) return;
if (x1<=p[x].h&&p[x].t<=x2)
{
p[x].change2(,y1,y2); return;
}
change1(x*,x1,x2,y1,y2); change1(x*+,x1,x2,y1,y2);
}
int query1(int x,int a,int b)
{
if (p[x].h==p[x].t)
{
return(p[x].query2(,b));
}
if (a>mid) return(query1(x*+,a,b));
else return(query1(x*,a,b));
}
int main()
{
freopen("noip.in","r",stdin);
freopen("noip.out","w",stdout);
cin>>k; int a1,b1,a2,b2;
for (int o=;o<=k;o++)
{
cin>>n>>m;
build1(,,n,n);
for (int i=;i<=m;i++)
{
cin>>c;
if (c=='C')
{
cin>>a1>>b1>>a2>>b2;
change1(,a1,a2,b1,b2);
}
if (c=='Q')
{
cin>>a1>>b1;
cout<<query1(,a1,b1);
}
}
}
}
poj 2155(未完成)的更多相关文章
- POJ 2155 D区段树
POJ 2155 D区段树 思考:D区段树是每个节点设置一个段树树. 刚開始由于题目是求A[I,J],然后在y查询那直接ans^=Map[i][j]的时候没看懂.后面自己把图画出来了才理解. 由于仅 ...
- POJ poj 2155 Matrix
题目链接[http://poj.org/problem?id=2155] /* poj 2155 Matrix 题意:矩阵加减,单点求和 二维线段树,矩阵加减,单点求和. */ using names ...
- POJ 2155 Matrix (D区段树)
http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 1 ...
- POJ 2155 Matrix【二维树状数组+YY(区间计数)】
题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...
- POJ 2155 Matrix(树状数组+容斥原理)
[题目链接] http://poj.org/problem?id=2155 [题目大意] 要求维护两个操作,矩阵翻转和单点查询 [题解] 树状数组可以处理前缀和问题,前缀之间进行容斥即可得到答案. [ ...
- 【树状数组】POJ 2155 Matrix
附一篇经典翻译,学习 树状数组 http://www.hawstein.com/posts/binary-indexed-trees.html /** * @author johnsondu * @ ...
- 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 ...
随机推荐
- Jquery中click事件重复执行的问题
平常没注意事件绑定问题,在此注意一下: function testClick(obj){ $("select").off().on("click", funct ...
- Linux 重启网卡失败 Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.
linux下重启网卡使用命令 : service network restart 时报错: [root@slave01 hadoop]# service network restart Startin ...
- 20155330 2016-2017-2 《Java程序设计》第六周学习总结
20155330 2016-2017-2 <Java程序设计>第六周学习总结 教材学习内容总结 学习目标 理解流与IO 理解InputStream/OutPutStream的继承架构 理解 ...
- mongoDB - 日常操作一
mongodb 启动方式 # 不启动认证 ./mongod --bind_ip 172.16.2.17 --port --fork --logpath=/opt/mongodb/mongodb.log ...
- [洛谷P3948]数据结构 题解(差分)
[洛谷P3948]数据结构 Description 最开始的数组每个元素都是0 给出n,opt ,min,max,mod 在int范围内 A: L ,R ,X 表示把[l,R] 这个区间加上X(数组的 ...
- mysql 开源~canal维护相关问题
一 简介:咱们来讨论下canal的一些技巧 二 场景 场景1 canal过滤指定库后,后端java调用读取相关数据时候出现大量的空事务,为何会出现空事务呢,空事务是由于配置了指定的过滤规则,导致了其他 ...
- JS判断页面是否出现滚动条
今天无聊,帮一个网友解决一个很无聊的问题,用JS判断页面是否出现滚动条,在网上看了一些代码,经过验证并不起作用,下面是在网上搜索到的代码: 当可视区域小于页面的实际高度时,判定为出现滚动条,即: if ...
- 从Linux内核中获取真随机数【转】
转自:http://www.cnblogs.com/bigship/archive/2010/04/04/1704228.html 内核随机数产生器 Linux内核实现了一个随机数产生器,从理论上说这 ...
- phantomjs 截取twitter的网页(动态生成的页面)
// This example shows how to render pages that perform AJAX calls// upon page load.//// Instead of w ...
- oracle客户端安装
一.引导安装并配置 1)下载客户端(两个文件) 2)选中两个压缩包解压到同一个文件夹下 3)点击setup 4)选择:创建和配置数据库桌面类选择安装目录,全局数据库名:orcl,密码admin口令管理 ...