分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=5e4+;
int n,m,T,c[N<<],lz[N<<];
void build(int rt,int l,int r){
lz[rt]=-;
if(l==r){c[rt]=;return;}
int m=(l+r)>>;
build(rt<<,l,m);
build(rt<<|,m+,r);
c[rt]=c[rt<<]+c[rt<<|];
}
void pushdown(int rt,int l,int r){
if(lz[rt]!=-){
int m=(l+r)>>;
c[rt<<]=lz[rt]*(m-l+);
c[rt<<|]=lz[rt]*(r-m);
lz[rt<<]=lz[rt<<|]=lz[rt];
lz[rt]=-;
}
}
int t;
void modify(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y){
c[rt]=t*(r-l+);
lz[rt]=t;
return;
}
int m=(l+r)>>;
pushdown(rt,l,r);
if(x<=m)modify(rt<<,l,m,x,y);
if(y>m)modify(rt<<|,m+,r,x,y);
c[rt]=c[rt<<]+c[rt<<|];
}
int ask(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y)return c[rt];
int m=(l+r)>>,ans=;
pushdown(rt,l,r);
if(x<=m)ans+=ask(rt<<,l,m,x,y);
if(y>m)ans+=ask(rt<<|,m+,r,x,y);
return ans;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
build(,,n);
while(m--){
int op,x,y;
scanf("%d%d%d",&op,&x,&y);
if(op==){
++x,++y;
printf("%d\n",y-x+-ask(,,n,x,y));
t=;modify(,,n,x,y);
continue;
}
++x;
y=min(y,ask(,,n,x,n));
if(!y){
printf("Can not put any one.\n");
continue;
}
int ans1,ans2;
int l=x,r=n;
while(l<r){
int mid=(l+r)>>,cur=ask(,,n,x,mid);
if(!cur)l=mid+;
else r=mid;
}
ans1=(l+r)>>;
l=x,r=n;
while(l<r){
int mid=(l+r)>>,cur=ask(,,n,x,mid);
if(cur<y)l=mid+;
else r=mid;
}
ans2=(l+r)>>;
t=;modify(,,n,ans1,ans2);
printf("%d %d\n",--ans1,--ans2);
}
printf("\n");
}
return ;
}

HDU4614 Vases and Flowers 二分+线段树的更多相关文章

  1. hdu4614 Vases and Flowers【线段树】【二分】

    Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to N ...

  2. HDU-4614 Vases and Flowers(线段树区间更新+二分查找)

    http://acm.hdu.edu.cn/showproblem.php?pid=4614 Time Limit: 4000/2000 MS (Java/Others)    Memory Limi ...

  3. HDU 4614 Vases and Flowers(二分+线段树区间查询修改)

    描述Alice is so popular that she can receive many flowers everyday. She has N vases numbered from 0 to ...

  4. HDU-4614 Vases and Flowers (线段树区间更新)

    题目大意:有n个花瓶,每个花瓶中只能放一朵花.两种操作,一种是从A开始放F朵花,如果有的花瓶中已经有花则跳过这个花瓶,往下一个花瓶放:第二种是将区间[A,B]之间花瓶中的花清空.如果是第一种操作,输出 ...

  5. HDU 4614 Vases and Flowers(线段树+二分)

    Vases and Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others ...

  6. HDU 4614 Vases and Flowers 【线段树】+【二分】

    <题目链接> 题目大意: 有n个花瓶,每个花瓶中只能放一朵花.两种操作,一种是从A开始放F朵花,如果有的花瓶中已经有花则跳过这个花瓶,往下一个花瓶放:第二种是将区间[A,B]之间花瓶中的花 ...

  7. 【HDU 4614】Vases and Flowers(线段树区间更新懒惰标记)

    题目0到n-1的花瓶,操作1在下标a开始插b朵花,输出始末下标.操作2清空[a,b]的花瓶,求清除的花的数量.线段树懒惰标记来更新区间.操作1,先查询0到a-1有num个空瓶子,然后用线段树的性质,或 ...

  8. HDU4614Vases and Flowers 二分+线段树;

    参考:https://blog.csdn.net/ophunter_lcm/article/details/9879495   题意: 有n个花瓶,有两种操作,1.从a开始放b朵花,有花的花瓶跳过,2 ...

  9. Vases and Flowers-HDU4614 二分+线段树

    题意: 给你N个花瓶,编号是0  到 N - 1 ,一开始每个花瓶都是空的,你有两个操作: 第一个操作: 从第x个花瓶起开始插花,总共插y束,如果遇到花瓶中有花就跳过这个花瓶,直到花插完或者 插到第N ...

随机推荐

  1. IOS调用相机相册

    #import "SendViewController.h"  //只能打开,没有加载图片的代码,老代码,供参考 #import <MobileCoreServices/UT ...

  2. bnuoj 29375 Two Strings(字符串?)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=29375 [题意]:可以对两字符串进行如下操作: 1.可以无损耗交换相邻两个字符(可以理解成交换任意字 ...

  3. Python系统调用——运行其他程序

    转载:http://blog.csdn.net/ssihc0/article/details/7738527 在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其 ...

  4. MySQL的基本命令

    MySQL的基本命令 启动:net start mySql; 进入:mysql -u root -p/mysql -h localhost -u root -p databaseName; 列出数据库 ...

  5. static 内部类

    一般情况下是不可以用static修饰类的.如果一定要用static修饰类的话,通常static修饰的是匿名内部类. 在一个类中创建另外一个类,叫做成员内部类.这个成员内部类可以静态的(利用static ...

  6. struts2 标签库 介绍

    struts2.0里的标签没有分类,只用在jsp头文件加上<%@ taglib prefix="s" uri="/struts-tags" %>就能 ...

  7. 【转】linux C++ 获取文件信息 stat函数详解

    stat函数讲解 表头文件:    #include <sys/stat.h>             #include <unistd.h>定义函数:    int stat ...

  8. linux和window下mkdir函数

    通过WIN32宏进行判断   window下mkdir函数   #include<direct.h> int _mkdir( const char *dirname );   linux下 ...

  9. HDU1171——Big Event in HDU(母函数)

    Big Event in HDU DescriptionNowadays, we all know that Computer College is the biggest department in ...

  10. svn的merge使用例子

    先说说什么是branch.按照Subversion的说法,一个branch是某个development line(通常是主线也即trunk)的一个拷贝,见下图: branch存在的意义在于,在不干扰t ...