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 ...
随机推荐
- 年轻人你活着不是为了看K线!
年轻人你活着不是为了看K线! 在网上看到一篇文章,写得还不错,转给大家看一下,内容如下: 这篇文章本来是该几年前写的,奉劝大家不要去玩股票.因为那个时候我的<中国崛起的经济学分析>这本 ...
- switch-case 执行顺序
switch(expression){ case value : //语句 break; //可选 case value : //语句 break; //可选 //你可以有任意数量的case语句 de ...
- js用ajax和不同页面的php互相传值的方法
js里的代码:<script> var json; //获取所有class名为zhi的标签 var zhi = document.getElementsByClassName('zhi') ...
- robotframework笔记13
变量 介绍 变量是不可或缺的功能机器人框架,他们可以 在大多数地方用于测试数据. 通常,他们使用 参数测试用例表中的关键字和关键字表,但是 也都设置允许变量的值. 一个正常的字 的名字 不能 指定一个 ...
- CSS:static/relative/absolute
static - default and this is the FLOW. ------------------------------------------------------------- ...
- addEventListener,attachEvent
addEventListener是js填加事件:用法如下: target.addEventListener(type,listener,useCapture) target: 文档节点.documen ...
- cf--------(div1)1A. Theatre Square
A. Theatre Square time limit per test 2 seconds memory limit per test 64 megabytes input standard in ...
- Android res/目录下子目录详解
Directory Resource Type animator/ XML files that define property animations. anim/ XML files that de ...
- 语句:分支语句、switch case ——7月22日
语句的类型包括:声明语句.表达式语句.选择语句.循环语句.跳转语句.异常语句 1.声明语句引:入新的变量或常量. 变量声明可以选择为变量赋值. 在常量声明中必须赋值. 例如: int i = 0;// ...
- Help Me Escape (ZOJ 3640)
J - Help Me Escape Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:32768KB ...