hdu3911 线段树 区间合并
//Accepted 3911 750MS 9872K
//线段树 区间合并
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
/**
* This is a documentation comment block
* 如果有一天你坚持不下去了,就想想你为什么走到这儿!
* @authr songt
*/
;
struct node
{
int l,r;
int L1,R1;
int L0,R0;
int sum1,sum0;
int change;
}f[imax_n*];
int a[imax_n];
int max(int a,int b)
{
return a>b?a:b;
}
int min(int a,int b)
{
return a<b?a:b;
}
//合并
//
void pushUp(int t)
{
*t].r-f[*t].l+;
*t+].r-f[*t+].l+;
f[t].L1=f[*t].L1;
*t].L1==lLen) f[t].L1+=f[*t+].L1;
f[t].R1=f[*t+].R1;
*t+].R1==rLen) f[t].R1+=f[*t].R1;
f[t].L0=f[*t].L0;
*t].L0==lLen) f[t].L0+=f[*t+].L0;
f[t].R0=f[*t+].R0;
*t+].R0==rLen) f[t].R0+=f[*t].R0;
f[t].sum1=max(f[*t].sum1,f[*t+].sum1);
f[t].sum1=max(f[t].sum1,f[*t].R1+f[*t+].L1);
f[t].sum0=max(f[*t].sum0,f[*t+].sum0);
f[t].sum0=max(f[t].sum0,f[*t].R0+f[*t+].L0);
}
void swap(int &a,int &b)
{
int t=a;
a=b;
b=t;
}
void pushDown(int t)
{
)
{
f[*t].change^=;
f[*t+].change^=;
f[t].change=;
swap(f[*t].L0,f[*t].L1);
swap(f[*t].R0,f[*t].R1);
swap(f[*t].sum0,f[*t].sum1);
swap(f[*t+].L0,f[*t+].L1);
swap(f[*t+].R0,f[*t+].R1);
swap(f[*t+].sum0,f[*t+].sum1);
}
}
void build(int t,int l,int r)
{
f[t].l=l;
f[t].r=r;
f[t].change=;
if (l==r)
{
)
{
f[t].L1=f[t].R1=;
f[t].L0=f[t].R0=;
f[t].sum1=;
f[t].sum0=;
}
else
{
f[t].L1=f[t].R1=;
f[t].L0=f[t].R0=;
f[t].sum1=;
f[t].sum0=;
}
return ;
}
;
build(*t,l,mid);
build(*t+,mid+,r);
pushUp(t);
}
void update(int t,int l,int r)
{
if (f[t].l==l && f[t].r==r)
{
f[t].change^=;
swap(f[t].L0,f[t].L1);
swap(f[t].R0,f[t].R1);
swap(f[t].sum0,f[t].sum1);
return ;
}
pushDown(t);
;
*t,l,r);
else
{
*t+,l,r);
else
{
update(*t,l,mid);
update(*t+,mid+,r);
}
}
pushUp(t);
}
int query(int t,int l,int r)
{
if (f[t].l==l && f[t].r==r)
{
return f[t].sum1;
}
pushDown(t);
;
*t,l,r);
else
{
*t+,l,r);
else
{
*t,l,mid);
*t+,mid+,r);
int ans=max(sum1,sum2);
//在左半区间的长度不应大于该段区间在左半区间的长度
ans=max(ans,min(f[*t].r-l+,f[*t].R1)+min(r-f[*t+].l+,f[*t+].L1));
return ans;
}
}
}
int n;
int Q,k,x,y;
void slove()
{
build(,,n);
scanf("%d",&Q);
;i<=Q;i++)
{
scanf("%d%d%d",&k,&x,&y);
if (x>y) swap(x,y);
)
{
printf(,x,y));
}
else
{
update(,x,y);
}
}
}
int main()
{
while (scanf("%d",&n)!=EOF)
{
;i<=n;i++)
scanf("%d",&a[i]);
slove();
}
;
}
hdu3911 线段树 区间合并的更多相关文章
- POJ 3667 Hotel(线段树 区间合并)
Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 ...
- HDU 3911 线段树区间合并、异或取反操作
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3911 线段树区间合并的题目,解释一下代码中声明数组的作用: m1是区间内连续1的最长长度,m0是区间内连续 ...
- HDU 3911 Black And White(线段树区间合并+lazy操作)
开始以为是水题,结果...... 给你一些只有两种颜色的石头,0为白色,1为黑色. 然后两个操作: 1 l r 将[ l , r ]内的颜色取反 0 l r 计算[ l , r ]内最长连续黑色石头的 ...
- HYSBZ 1858 线段树 区间合并
//Accepted 14560 KB 1532 ms //线段树 区间合并 /* 0 a b 把[a, b]区间内的所有数全变成0 1 a b 把[a, b]区间内的所有数全变成1 2 a b 把[ ...
- poj3667 线段树 区间合并
//Accepted 3728 KB 1079 ms //线段树 区间合并 #include <cstdio> #include <cstring> #include < ...
- 线段树(区间合并) POJ 3667 Hotel
题目传送门 /* 题意:输入 1 a:询问是不是有连续长度为a的空房间,有的话住进最左边 输入 2 a b:将[a,a+b-1]的房间清空 线段树(区间合并):lsum[]统计从左端点起最长连续空房间 ...
- HDU 3308 LCIS (线段树区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...
- SPOJ GSS1_Can you answer these queries I(线段树区间合并)
SPOJ GSS1_Can you answer these queries I(线段树区间合并) 标签(空格分隔): 线段树区间合并 题目链接 GSS1 - Can you answer these ...
- 树链剖分——线段树区间合并bzoj染色
线段树区间合并就挺麻烦了,再套个树链就更加鬼畜,不过除了代码量大就没什么其他的了.. 一些细节:线段树每个结点用结构体保存,pushup等合并函数改成返回一个结构体,这样好写一些 struct Seg ...
随机推荐
- Question store (Repeated review)
题目36 - ACM在线评测系统http://acm.nyist.net/JudgeOnline/problem.php?pid=36 用户名密码INVATION 讲道理太卡 第一:要注意不同的函数 ...
- nodeschool.io 8
~~ HTTP COLLECT ~~ Write a program that performs an HTTP GET request to a URL provided toyou as the ...
- Maximal Rectangle [LeetCode]
Problem Description: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle co ...
- 读书笔记1: 资源地址—通用资源的标识符(URI)
例子: https://msdn.microsoft.com/zh-cn/library/system.uri(v=vs.110).aspx 解释:协议://主机[:端口号]/绝对路径[参数] 对应的 ...
- node 事件循环
什么是事件循环 Node只运行在一个单一线程上,至少从Node.js开发者的角度是这样的.在底层, Node是通过libuv来实现多线程的. Libuv库负责Node API的执行.它将不同的任务分配 ...
- [转]RAID技术介绍和总结
以下内容转自伯乐在线:http://blog.jobbole.com/83808/ 原文出处: 涯余(@若东临于沧海) ---------------------------------------- ...
- 引用CSS文件到html网页里方法
引用CSS文件到Html方法-css引入,css引用 使用不同的方法来引用css样式表,最终到达的效果相同,但是使用不同方法应用的css文件将影响到SEO及网页打开速度效率. html引用cs ...
- ANGULARJS 出错解决
先上代码 程序的意思是使用eval更改指令父scope的数据,在调用$digest 这样就出错了,出错信息如下: 解决办法: 增加timeout事件,具体原因还不是很清楚,反正问题目前是解决了.
- LinearLayout练习
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- excel的变量
因需要定制游戏的公式,公式是以一个系数乘以等级,我想达到修改系数,每个等级对应的值就立即显示出来, 但把系数写在一个单元格,一拉,系数单元格也会跟着增长行数--不是我想要的: 但只要把系数单元格改成变 ...