//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 线段树 区间合并的更多相关文章

  1. POJ 3667 Hotel(线段树 区间合并)

    Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 ...

  2. HDU 3911 线段树区间合并、异或取反操作

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3911 线段树区间合并的题目,解释一下代码中声明数组的作用: m1是区间内连续1的最长长度,m0是区间内连续 ...

  3. HDU 3911 Black And White(线段树区间合并+lazy操作)

    开始以为是水题,结果...... 给你一些只有两种颜色的石头,0为白色,1为黑色. 然后两个操作: 1 l r 将[ l , r ]内的颜色取反 0 l r 计算[ l , r ]内最长连续黑色石头的 ...

  4. HYSBZ 1858 线段树 区间合并

    //Accepted 14560 KB 1532 ms //线段树 区间合并 /* 0 a b 把[a, b]区间内的所有数全变成0 1 a b 把[a, b]区间内的所有数全变成1 2 a b 把[ ...

  5. poj3667 线段树 区间合并

    //Accepted 3728 KB 1079 ms //线段树 区间合并 #include <cstdio> #include <cstring> #include < ...

  6. 线段树(区间合并) POJ 3667 Hotel

    题目传送门 /* 题意:输入 1 a:询问是不是有连续长度为a的空房间,有的话住进最左边 输入 2 a b:将[a,a+b-1]的房间清空 线段树(区间合并):lsum[]统计从左端点起最长连续空房间 ...

  7. HDU 3308 LCIS (线段树区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...

  8. SPOJ GSS1_Can you answer these queries I(线段树区间合并)

    SPOJ GSS1_Can you answer these queries I(线段树区间合并) 标签(空格分隔): 线段树区间合并 题目链接 GSS1 - Can you answer these ...

  9. 树链剖分——线段树区间合并bzoj染色

    线段树区间合并就挺麻烦了,再套个树链就更加鬼畜,不过除了代码量大就没什么其他的了.. 一些细节:线段树每个结点用结构体保存,pushup等合并函数改成返回一个结构体,这样好写一些 struct Seg ...

随机推荐

  1. 小韦系统装工行网银U盾驱动的方法

    小韦系统装工行网银U盾驱动的方法 拷贝文件.bat @echo 开始注册echo n|copy /-y scarddlg.dll %windir%\system32\echo n|copy /-y w ...

  2. 国内外比较出名的做MySQL的公司以及原因

      做MySQL比较出名的公司和原因 公司 原因 Oracle 名门正派 MariaDB 不断出MySQL新feature,功能比Oracle版的要多,更新速度快 Percona DBA工具出名 we ...

  3. 那些年独自踩过的flascc的坑

    [一个工程中使用多个flascc编译出来的swc] 1.如果是swf工程, 工程中同时使用多个flascc编译出来的swc, 可以顺利通过. 2.如果是swc工程, 工程中同时使用多个flascc编译 ...

  4. linux笔记:用户管理命令和用户组管理命令

    用户管理命令 命令名称:useradd功能:添加用户(添加完后不能立即使用,必须用passwd修改用户密码后才能使用)用法:useradd [选项] 用户名选项参数:-u 手工指定用户的UID-d 手 ...

  5. Intellij IDEA中部署Tomcat报错“war exploded: Server is not connected. Deploy is not available”

    最近将本机的Tomcat 7卸载重装了Tomcat 9后,在IDEA中运行Tomcat老是报错,一直未找到解决问题的办法. 只能讲Tomcat重新退回到版本7,才重新再IDEA中运行正常.

  6. DSP28377S - ADC学习编程笔记

    DSP28377S -  ADC学习编程笔记 彭会锋 2016-08-04  20:19:52 1 ADC类型导致的配置区别 F28377S的ADC类型是Type 4类型,我的理解是不同类型的ADC采 ...

  7. Ubuntu下配置和编译cpp-ethereum客户端

    Ethereum,中文翻译是“以太坊”,是一个公有区块链的开源项目.因为以太坊是基于P2P网络所以没有中心节点,所以用户仅安装Ethereum客户端即可连入Ethereum公共网络或者在自己的test ...

  8. (29)odoo的可用小图标

    * 系统的小图标都采用了 fontawesome    官网是 http://fontawesome.dashgame.com/    * 运用小图标    # 首先打开官网 http://fonta ...

  9. 学习HTML5之新特性标签一览(详细)

    HTML5又2008年诞生,HTML5大致可以等同于=html+css3+javascriptapi.... so --->支持css3强大的选择器和动画以及javascript的新的函数 先来 ...

  10. kwicks插件学习

    /* Kwicks for jQuery (version 1.5.1) Copyright (c) 2008 Jeremy Martin http://www.jeremymartin.name/p ...