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 ...
随机推荐
- 我的vim插件配置
set nocompatible " be iMproved, required filetype off " required " set the runtime pa ...
- angularjs指令中scope参数 true、false、{} 的区别详解
scope 有三个参数 true.false.{} scope 默认是 false,当 scope设置为true时,会从父作用域继承并创建一个新的作用域对象, 按照true .false的反向思维,我 ...
- Database学习 - mysql 数据库 数据操作
mysql数据操作 查询语法 select * | field1,field1 ... from 表名 where 条件 group by 字段 having 筛选 order by 字段 limit ...
- Struts的JSON机制
需要加入jar包 Struts的JSON帮助我们自动将对象解析为JSON对象,不用我门借助第三方进行JSON的解析 .具体的使用机制如下: 1.Action类 package StrutsJSON; ...
- 【ARTS】01_09_左耳听风-20190107~20190113
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- haar特征(转)
转载链接:http://blog.csdn.net/lanxuecc/article/details/52222369 Haar特征 Haar特征原理综述 Haar特征是一种反映图像的灰度变化的,像素 ...
- Linux内核驱动之延时 【转】
转自:http://blog.chinaunix.net/uid-24219701-id-3288103.html jiffies 计数器 定时器中断由系统定时硬件以规律地间隔产生; 这个间隔在启动 ...
- 汇编语言转换成c语言,或者汇编语言转换成golang的汇编,c语言转换成golang的方法
https://github.com/minio/c2goasm http://microapl.com/asm2c/index.html 收费的 https://gith ...
- 【转】SourceInsight4破解笔记
时隔好多年,sourceinsight4以迅雷不及掩耳之势的来了.与3.5相比,sourceinsight4多了代码折叠以及文件标签功能,可谓是让sourceinsight迷兴奋了好几晚上.废话不多说 ...
- oracle move 释放 表空间
使用sqlplus 操作 alter table TEST_TB1 move storage(initial 64K); alter table TEST_TB1 move ; select SEG ...