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 ...
随机推荐
- 浅谈cookie与session的区别
cookie用的是在客户端保持状态的方案(它是在用户端的会话状态的存贮机制),前端也可以来设置他 所有浏览器都识别,并且会缓存在浏览器中. cookie是以key=value这种键值对的形式保存,每个 ...
- jQuery 选择城市,显示对应的即时时区时间
因客户需要,我们CRM系统中,jQuery 弄个时区插件 如图: HTML: <div id="cityDate"> <i class="P_arrow ...
- 腾讯云Unbuntu服务器安装桌面环境
进入命令行 1.sudo apt-get install xinit 2.sudo apt-get install gdm 3.sudo apt-get install ubuntu-desktop ...
- ssh 登录出现Are you sure you want to continue connecting (yes/no)?解决方法
ssh 登录出现Are you sure you want to continue connecting (yes/no)?解决方法 1,可以使用ssh -o 的参数进行设置例如: ssh -o St ...
- float/double 浮点数据*100精度丢失问题
工作中微信支付碰到的一个问题,金额是float数字,微信参数需要分且必须是整数,所以*100的时候就有问题了 System.out.println(9.9f*100); //989.99994Syst ...
- BackBone结合ASP.NET MVC实现页面路由操作
1. 问题的背景 什么是页面路由操作,就是通过浏览器地址栏的标记来实现页面内部的一些操作,这些操作具有异步性和持久性.应用场景主要有页面操作过程中的添加收藏夹的操作.后退操作等过程中能完全恢复界面. ...
- nodejs xpath
var fs = require('fs');var xpath = require('xpath');var dom = require('xmldom').DOMParser; // Read t ...
- vue学习生命周期(created和mounted区别)
created:在模板渲染成html前调用,即通常初始化某些属性值,然后再渲染成视图(例如ajax请求列表). mounted:在模板渲染成html后调用,通常是初始化页面完成后,再对html的dom ...
- oracle 命令行
背景 看到当初竟然记录了命令行,想想自己用了多久才知道了命令行,好像有几年了吧.当时还记得买了两本oracle9的管理书籍,就跟见了九阴真经一样,从头到尾熟悉了好几遍,不过也大部分忘了交给老师了.以下 ...
- zabbix系列(七)zabbix3.0添加对tcp连接数及状态的监控
原理: netstat -an|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}' TIME_WAIT 79 ESTABLISHED 6 LISTE ...