poj3667 线段树 区间合并
//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 线段树 区间合并的更多相关文章
- poj3667(线段树区间合并&区间查询)
题目链接: http://poj.org/problem?id=3667 题意:第一行输入 n, m表示有 n 间房间(连成一排的), 接下来有 m 行输入, 对于接下来的 m 行输入: 1 x : ...
- poj3667 Hotel (线段树 区间合并)
poj3667 HotelTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 18925 Accepted: 8242Descripti ...
- poj-3667(线段树区间合并)
题目链接:传送门 参考文章:传送门 思路:线段树区间合并问题,每次查询到满足线段树的区间最左值,然后更新线段树. #include<iostream> #include<cstdio ...
- 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 把[ ...
- hdu3911 线段树 区间合并
//Accepted 3911 750MS 9872K //线段树 区间合并 #include <cstdio> #include <cstring> #include < ...
- 线段树(区间合并) POJ 3667 Hotel
题目传送门 /* 题意:输入 1 a:询问是不是有连续长度为a的空房间,有的话住进最左边 输入 2 a b:将[a,a+b-1]的房间清空 线段树(区间合并):lsum[]统计从左端点起最长连续空房间 ...
随机推荐
- js时间差转为天数
function DateDiff(sDate1, sDate2){ //sDate1和sDate2是2006-12-18格式 var aDate, oDate1, oDate2, iDays aDa ...
- 第一堂java web课
一天的课程上完,虽然很累,但是因为自己的收获,所以我很开心. 第一节课老师带我们大家学习了HTML,学了很多标签,比如:html,head,body <html></html> ...
- $.get的重写
window.meng = window.meng || {}; (function () { function Get() { this.def = $.Deferred(); } Get.prot ...
- python 练习 29
Python Number 数据类型用于存储数值. 数据类型是不允许改变的,这就意味着如果改变 Number 数据类型的值,将重新分配内存空间. 以下实例在变量赋值时 Number 对象将被创建: v ...
- robotframework笔记9
列表和字典 通过专用关键字创建了列表和字典.我们将在这里看到创建的两个例子 ︰ 选择 *** Settings *** Library BuiltIn Library Collections *** ...
- 10款实用Android UI 开发框架
1. ActionBarSherlock ActionBarSherlock是一个独立的Android设计库,可以让Android 2.x的系统也能使用ActionBar.此外,ActionBarSh ...
- 菜单滑动-menu swipe
http://tympanus.net/codrops/ http://www.idangero.us/sliders/swiper/index.php //触摸滑动
- SpringMVC 配置定时执行任务
1.在SpringMVC配置文件中添加 xmlns:task="http://www.springframework.org/schema/task" http://www.spr ...
- HTML中的一些常见的事件句柄
onclick 所有类似按钮的表单元素和标记<a>及<area>都支持该处理程序.当用户点击元素时会触发它.如果onclick处理程序返回false,则浏览器不执行任何与按钮或 ...
- OpenLDAP使用疑惑解答及使用Java完成LDAP身份认证
导读 LDAP(轻量级目录访问协议,Lightweight Directory Access Protocol)是实现提供被称为目录服务的信息服务.目录服务是一种特殊的数据库系统,其专门针对读取,浏览 ...