//Accepted    3728 KB    1079 ms
 //线段树 区间合并
 #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 sum1;
     int change;   //change -1 区间没有改变  0区间变成0 1区间变成1
 }f[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 swap(int &a,int &b)
 {
     int t=a;
     a=b;
     b=t;
 }
 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].sum1=max(f[*t].sum1,f[*t+].sum1);
     f[t].sum1=max(f[t].sum1,f[*t].R1+f[*t+].L1);
 }
 void pushDown(int t)
 {
     )
     {
         f[*t].change=f[t].change;
         f[*t+].change=f[t].change;
         f[t].change=-;
         f[*t].L1=f[*t].R1=f[*t].sum1=(f[*t].r-f[*t].l+)*f[*t].change;
         f[*t+].L1=f[*t+].R1=f[*t+].sum1=(f[*t+].r-f[*t+].l+)*f[*t+].change;
     }
 }
 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].sum1=;
         return ;
     }
     ;
     build(*t,l,mid);
     build(*t+,mid+,r);
     pushUp(t);
 }
 void update(int t,int l,int r,int c)
 {
     if (f[t].l==l && f[t].r==r)
     {
         f[t].change=c;
         f[t].L1=f[t].R1=f[t].sum1=f[t].change*(f[t].r-f[t].l+);
         return ;
     }
     pushDown(t);
     ;
     *t,l,r,c);
     else
     {
         *t+,l,r,c);
         else
         {
             update(*t,l,mid,c);
             update(*t+,mid+,r,c);
         }
     }
     pushUp(t);
 }
 int query(int t,int k)
 {
     //printf("f[%d].sum1=%d\n",t,f[t].sum1);
     if (f[t].l==f[t].r)
     {
         ;
         else return f[t].l;
     }
     pushDown(t);
     ;
     *t].sum1>=k) *t,k);
     *t].R1+f[*t+].L1>=k) *t].r-f[*t].R1+;
     *t+].sum1>=k) *t+,k);
     ;
 }
 int n,m;
 int op,x,y;
 void slove()
 {
     build(,,n);
     ;i<=m;i++)
     {
         scanf("%d",&op);
         )
         {
             scanf("%d",&x);
             ,x);
             //printf("query=%d\n",t);
             )
             printf("0\n");
             else
             {
                 printf("%d\n",t);
                 update(,t,t+x-,);
             }
         }
         else
         {
             scanf("%d%d",&x,&y);
             update(,x,x+y-,);
         }
     }
 }
 int main()
 {
     while (scanf("%d%d",&n,&m)!=EOF)
     {
         slove();
     }
     ;
 }

poj3667 线段树 区间合并的更多相关文章

  1. poj3667(线段树区间合并&区间查询)

    题目链接: http://poj.org/problem?id=3667 题意:第一行输入 n, m表示有 n 间房间(连成一排的), 接下来有 m 行输入, 对于接下来的 m 行输入: 1 x : ...

  2. poj3667 Hotel (线段树 区间合并)

    poj3667 HotelTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 18925 Accepted: 8242Descripti ...

  3. poj-3667(线段树区间合并)

    题目链接:传送门 参考文章:传送门 思路:线段树区间合并问题,每次查询到满足线段树的区间最左值,然后更新线段树. #include<iostream> #include<cstdio ...

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

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

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

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

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

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

  7. HYSBZ 1858 线段树 区间合并

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

  8. hdu3911 线段树 区间合并

    //Accepted 3911 750MS 9872K //线段树 区间合并 #include <cstdio> #include <cstring> #include < ...

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

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

随机推荐

  1. android fragment 博客 学习记录

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/37992017 上篇博客中已经介绍了Fragment产生原因,以及一些基本的用法和 ...

  2. jQuery Ajax学习

    地址:http://www.w3school.com.cn/jquery/jquery_ref_ajax.asp

  3. android 内存泄露之jni local reference table overflow (max=512)

    在android项目中要实现一个需求 为了性能的要求只能用c代码来实现功能. 这样就牺牲了java跨平台性. 通过加载.so的方式,把用c实现的模块集成到app中. android提供jni层,作为一 ...

  4. 通过VBA实现checkbox的全选和反选

    checkbox的全选和反选可以通过VBA来控制,这种设计常见于一些交互式报表,代码如下: 1.分成两个IF判断 Private Sub CheckBox1_Click()  ‘checkbox为总控 ...

  5. python知识总结

    LIST:Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素,用[]包裹.例如 classmates = ['Michael', 'Bob', 'T ...

  6. js——常见的小方法

    1.随机得到是六位数,可以当做“密码”来使用: Math.random().toString().substr(2, 6):

  7. UESTC 2016 Summer Training #1 Div.2

    最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria ( ...

  8. Dapper使用

    公司的项目使用了Dapper做数据库连接处理,感觉不错,自己研究一下怎么用. 在网上找了找资料对Dapper都比较推崇.主要是两个方面,一个是连接速度很快,一个是代码开源且简单,只有一个SqlMapp ...

  9. Ubuntu 下Eclipse 安装SVN

    如果尚未安装Eclipse,先安装:也可以直接下载Google提供的ADT Bundle. sudo apt-get install eclipse 安装Subversion sudo apt-get ...

  10. Floyd 算法的动态规划本质

    [转载自:http://www.cnblogs.com/chenying99/p/3932877.html] Floyd–Warshall(简称Floyd算法)是一种著名的解决任意两点间的最短路径(A ...