线段树套线段树模板题

链接: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(未完成)的更多相关文章

  1. POJ 2155 D区段树

    POJ 2155  D区段树 思考:D区段树是每个节点设置一个段树树. 刚開始由于题目是求A[I,J],然后在y查询那直接ans^=Map[i][j]的时候没看懂.后面自己把图画出来了才理解. 由于仅 ...

  2. POJ poj 2155 Matrix

    题目链接[http://poj.org/problem?id=2155] /* poj 2155 Matrix 题意:矩阵加减,单点求和 二维线段树,矩阵加减,单点求和. */ using names ...

  3. POJ 2155 Matrix (D区段树)

    http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 1 ...

  4. POJ 2155 Matrix【二维树状数组+YY(区间计数)】

    题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  5. POJ 2155 Matrix(树状数组+容斥原理)

    [题目链接] http://poj.org/problem?id=2155 [题目大意] 要求维护两个操作,矩阵翻转和单点查询 [题解] 树状数组可以处理前缀和问题,前缀之间进行容斥即可得到答案. [ ...

  6. 【树状数组】POJ 2155 Matrix

    附一篇经典翻译,学习 树状数组  http://www.hawstein.com/posts/binary-indexed-trees.html /** * @author johnsondu * @ ...

  7. POJ 2155 Matrix

    二维树状数组....                          Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  8. poj 2155:Matrix(二维线段树,矩阵取反,好题)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17880   Accepted: 6709 Descripti ...

  9. POJ 2155 Matrix (二维线段树)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17226   Accepted: 6461 Descripti ...

随机推荐

  1. Neural Networks and Deep Learning 课程笔记(第三周)浅层神经网络(Shallow neural networks)

    3.1 神经网络概述(Neural Network Overview ) (神经网络中,我们要反复计算a和z,最终得到最后的loss function) 3.2 神经网络的表示(Neural Netw ...

  2. Bootstrap --对话框及提示框的处理和优化

    源模态框使用:http://www.runoob.com/bootstrap/bootstrap-modal-plugin.html <!-- 按钮触发模态框 --> <button ...

  3. C#字体与Rectangle简单对应关系

    在1920*1080 无缩放分辨率下,Rectangle要至少是字体的2倍+2才不会被遮挡.

  4. Hibernate添加日志--log4j

    需要导入 slf4j-log4j12-1.6.2.jar slf4j-api-1.6.2.jar log4j-1.2.16.jar 三个jar文件 编写properties文件,建议将日志输出级别设置 ...

  5. VxWorks Fuzzing 之道:VxWorks 工控实时操作系统漏洞挖掘调试与利用揭秘

    转载:freebuf 0×00 前言 关于VxWorks,这里引用44CON议题<攻击 VxWorks:从石器时代到星际>探究 一文章中的介绍: VxWorks 是世界上使用最广泛的一种在 ...

  6. 汕头市队赛 SRM 07 D 天才麻将少女kpm

    这道题放了很久还是回来补了 D 天才麻将少女KPM SRM 07 背景&&描述 天才麻将少女KPM立志要在日麻界闯出一番名堂.     KPM上周叒打了n场麻将,但她这次又没控分,而且 ...

  7. Linux - 系统资源

    查看剩余内存 free -m #-/+ buffers/cache: #6458M为真实使用内存 1649M为真实剩余内存(剩余内存+缓存+缓冲器) #linux会利用所有的剩余内存作为缓存,所以要保 ...

  8. 日期与时间控件QDate, QTime, QDateTime

    QDate类用于处理公历日期.QTime类用于处理时间.QDateTime类将QDate对象和QTime对象整合为一个对象 QDate: from PyQt5.QtCore import QDate, ...

  9. 如何在同一台服务器上部署两个tomcat

    因为测试的需要,有时我们必须在同一个服务器上部署两个tomcat,然后去做应用的部署,那么很多同学可能会觉得比较为难,找的资料也比较的不齐全,那么今天华华就来给大家讲讲如何部署2个tomcat,并能够 ...

  10. java gc

    mark下来 https://plumbr.eu/handbook/what-is-garbage-collection