思路:当k为1的时候,用二分法查询包含有f个空瓶的上界r,然后更新会方便很多,直接更新区间(a,r)了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define lson(x) (x<<1)
#define rson(x) ((x<<1)+1)
#define mid ((tree[po].l+tree[po].r)>>1)
#define inf 1<<30
#define Maxm 1000000
#define Maxn 60000
using namespace std;
struct Tree{
int l,r,left,up;
}tree[Maxm];
int flag=,ans,fir;
void buildTree(int l,int r,int po)
{
tree[po].l=l,tree[po].r=r;
tree[po].left=r-l+;
tree[po].up=;
if(l==r)
return ;
buildTree(l,mid,lson(po));
buildTree(mid+,r,rson(po));
}
void down(int po)
{ if(!tree[po].left)
{
tree[po].up=;
tree[lson(po)].left=;
tree[rson(po)].left=;
tree[rson(po)].up=;
tree[lson(po)].up=;
return ;
}
if(!tree[po].up) return ;
tree[lson(po)].left=mid-tree[po].l+;
tree[rson(po)].left=tree[po].r-mid;
tree[rson(po)].up=;
tree[lson(po)].up=;
tree[po].up=;
}
void update(int l,int r,int po)
{
if(l<=tree[po].l&&r>=tree[po].r)
{
ans+=tree[po].r-tree[po].l+-tree[po].left;
tree[po].left=tree[po].r-tree[po].l+;
tree[po].up=;
return ;
}
down(po);
if(r<=mid)
update(l,r,lson(po));
else
if(l>mid)
update(l,r,rson(po));
else{
update(l,r,lson(po));
update(l,r,rson(po));
}
tree[po].left=tree[lson(po)].left+tree[rson(po)].left;
}
int findTree(int l,int r,int po)
{
if(l<=tree[po].l&&r>=tree[po].r)
{
return tree[po].left;
}
down(po);
int temp=;
if(r<=mid)
temp=findTree(l,r,lson(po));
else
if(l>mid)
temp=findTree(l,r,rson(po));
else{
temp=findTree(l,r,lson(po));
temp+=findTree(l,r,rson(po));
}
tree[po].left=tree[lson(po)].left+tree[rson(po)].left;
return temp;
}
void Insert(int l,int r,int po)
{
if(l<=tree[po].l&&r>=tree[po].r)
{
if(tree[po].left==tree[po].r-tree[po].l+&&!flag)
flag=,fir=tree[po].l;
if(flag)
{
tree[po].left=;
return ;
}
}
if(!tree[po].left)
return ;
down(po);
if(r<=mid)
Insert(l,r,lson(po));
else
if(l>mid)
Insert(l,r,rson(po));
else{
Insert(l,r,lson(po));
Insert(l,r,rson(po));
}
tree[po].left=tree[lson(po)].left+tree[rson(po)].left;
}
int main()
{
int n,m,k,a,b,i,j,t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
buildTree(,n-,);
for(i=;i<=m;i++)
{
scanf("%d%d%d",&k,&a,&b);
if(k==)
{
flag=;
int l,r,Mid,temp;
temp=findTree(a,n-,);
if(temp<b)
b=temp;
l=a,r=n-;
while(r>l)
{
Mid=(l+r)>>;
temp=findTree(a,Mid,);
if(temp>=b)
r=Mid;
else
l=Mid+;
}
Insert(a,r,);
if(!flag)
printf("Can not put any one.\n");
else
printf("%d %d\n",fir,r);
}
else
{
ans=;
update(a,b,);
printf("%d\n",ans);
}
}
printf("\n");
}
return ;
}

hdu 4614 线段树的更多相关文章

  1. L - Vases and Flowers HDU - 4614 线段树+二分

    题意 给出一排空花瓶 有两种操作  1是 从A花瓶开始放F朵花 如果当前瓶有花就跳过前往下一个 直到花用完或者 瓶子到了最后一个为止 输出 成功放花的第一个和最后一个  如果没有输出 can not. ...

  2. HDU 4614 线段树+二分查找

    Vases and Flowers 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4614 Problem Description Alice is s ...

  3. hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  4. hdu 3974 线段树 将树弄到区间上

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. hdu 3436 线段树 一顿操作

    Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  6. hdu 3397 线段树双标记

    Sequence operation Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. hdu 4578 线段树(标记处理)

    Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) ...

  8. hdu 4533 线段树(问题转化+)

    威威猫系列故事——晒被子 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Tot ...

  9. hdu 2871 线段树(各种操作)

    Memory Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

随机推荐

  1. TTL电平、CMOS电平、RS232电平的区别

    工作中遇到一个关于电平选择的问题,居然给忘记RS232电平的定义了,当时无法反应上来,回来之后查找资料才了解两者之间的区别,视乎两年多的时间,之前非常熟悉的一些常识也开始淡忘,这个可不是一个好的现象. ...

  2. VC 各种情况下的窗口句柄的获取

    动窗口的句柄.否则,返回值为NULL. GetSafeHwnd 函数功能:获取某个窗口对象(CWnd的派生对象)指针的句柄(HWND)时,最安全的方法是使用GetSafeHwnd()函数. 通过下面的 ...

  3. Java学习笔记(二):String

    String 在Java中String是作为引用对象存在的一种数据类型,用来保存字符串. 实例化和赋值 //直接声明 String s1 = "Hello world!"; //通 ...

  4. -webkit-appearance: none;去处select默认小箭头样式

    Html <select class="sel_house_type"> <option value="0">请选择</optio ...

  5. The plot Function in matlab

    from http://pundit.pratt.duke.edu/wiki/MATLAB:Plotting The plot Function The plot function is used t ...

  6. .Net转前端

    坚持 OR 方向 转前端,去折腾CSS JS 各种神奇的移动端框架: Web App H5 前端 前端工程师=javascript+N种技能,即一专多长: JavaScript 世界,Node.js, ...

  7. Codeforces Round #280 (Div. 2) D. Vanya and Computer Game 二分

    D. Vanya and Computer Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  8. asp.net mvc控制器动作体返回ImageResult,可作验证码

    public ActionResult Img() { // 获取博客园空间顶部的banner图片 WebRequest req = WebRequest.Create("http://sp ...

  9. python selenium自动化(一)点击页面链接测试

    需求:现在有一个网站的页面,我希望用python自动化的测试点击这个页面上所有的在本窗口跳转,并且是本站内的链接,前往到链接页面之后在通过后退返回到原始页面. 要完成这个需求就必须实现3点: 1. 找 ...

  10. javascript遍历数组

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...