//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. The Daligner Overlap Library

    /************************************************************************************\ * * * Copyrig ...

  2. 修复 SQLite 数据库文件

    目 录 第1章 说明    1 1 下载SQLite Tools    1 2 运行    2 第1章 说明 笔者编写的一个程序,无法往 SQLite 数据库文件里写数据.使用SQLiteSpy打开该 ...

  3. 图片填充UIImageView大小不对

    http://www.2cto.com/kf/201507/412894.html UIView的contentMode属性: 默认为Scale To Fill,会保留view的比例,不会完全按照设定 ...

  4. MySQL索引实现

    摘自:http://blog.codinglabs.org/articles/theory-of-mysql-index.html 在MySQL中,索引属于存储引擎级别的概念,不同存储引擎对索引的实现 ...

  5. Stylus Studio的安装与卸载

  6. java.io.FileOutputStream类的5个构造方法

    java.io.FileOutputStream的构造函数: ①FileOutputStream(File file) ②FileOutputStream(String name) ③FileOutp ...

  7. js 日期时间控制器

    /////////////////////////调用实例 // <div> // <span>交易查询:</span> <span>从 // < ...

  8. sharepoint workflow不能正常使用

    程序集“Microsoft.SharePoint.WorkflowServices, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce ...

  9. HBase High Level Architecutre

  10. thinking in java 之Reference类的使用

    Reference是java中的特殊引用类.描述的是特殊作用(主要是关于垃圾回收对象)的引用. 它有3个子类: 1.SoftReference; 2.WeakReference 3.PhantomRe ...