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 ...
随机推荐
- cpu load过高问题排查
load average的概念 top命令中load average显示的是最近1分钟.5分钟和15分钟的系统平均负载. 系统平均负载被定义为在特定时间间隔内运行队列中(在CPU上运行或者等待运行多少 ...
- Mac下IntelliJ IDEA快捷键大全
Mac键盘符号和修饰键说明⌘ Command⇧ Shift⌥ Option⌃ Control↩︎ Return/Enter⌫ Delete⌦ 向前删除键(Fn+Delete)↑ 上箭头↓ 下箭头← 左 ...
- dijkstra补充
dijkstra主要写法: priority_queue<pair<int,int> >q; //大根堆 //dis第一维为dis的相反数 void dijkstra(){ m ...
- JavaScript之原生接口类设计
//接口类 var Interface = function(name , methods){ if(arguments.length!=2){ ...
- [洛谷P3948]数据结构 题解(差分)
[洛谷P3948]数据结构 Description 最开始的数组每个元素都是0 给出n,opt ,min,max,mod 在int范围内 A: L ,R ,X 表示把[l,R] 这个区间加上X(数组的 ...
- CF101D Castle
传送门 首先,一定要把所有点遍历一遍,这时答案应该是\(\frac{\sum 某个点第一次被遍历的时间点}{n-1}\quad\),而且每条边只能走两次,所以每次要遍历完某棵子树才能遍历其它子树. 考 ...
- python 错误--UnboundLocalError: local variable '**' referenced before assignment
val = 9 def test(flag): if flag: val = 1 else: print("test") return val if __name__ == '__ ...
- JS禁止右键查看源码,禁止复制,复制内容到剪切板
有时候我们希望自己的网页源码不被查看,这时需要关掉鼠标的右击事件;有时候我们也希望禁止选择页面内容Ctrl+C复制. 1.禁止右键查看源码; <script> //设置右键事件 funct ...
- oracle查询所有的表明
如果是用该用户登录使用以下语句: SELECT * FROM USER_TABLES; 如果是用其他用户: SELECT * FROM ALL_TABLES WHERE OWNER='USER_NAM ...
- MySQL— 基础
目录 一.MySQL概述 二.下载安装 三.数据库操作 四.数据表操作 五.表内容操作 一.MySQL概述 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracl ...