http://acm.hdu.edu.cn/showproblem.php?pid=4614

线段树的各种操作 写的有点乱 求插入位置是以区间K值的方法求出的 向下更新

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 50010
int s[N<<],lz[N<<];
void build(int l,int r,int w)
{
s[w] = r-l+;
lz[w] = -;
if(l==r)
{
s[w] = ;
return ;
}
int m = (l+r)>>;
build(l,m,w<<);
build(m+,r,w<<|);
}
void pushup(int w)
{
s[w] = s[w<<]+s[w<<|];
}
void pushdown(int l,int r,int w)
{
int m = (l+r)/;
if(lz[w]!=-)
{
lz[w<<] = lz[w<<|] = lz[w];
if(lz[w])
{
s[w<<] = m-l+;
s[w<<|] = r-m;
}
else
s[w<<] = s[w<<|] = ;
lz[w] = -;
}
}
int query(int p,int l,int r,int w)
{
if(l==r)
{
return l;
}
pushdown(l,r,w);
int m = (l+r)>>;
if(p<=s[w<<])
return query(p,l,m,w<<);
else
return query(p-s[w<<],m+,r,w<<|);
}
void update(int d,int a,int b,int l,int r,int w)
{
if(a<=l&&b>=r)
{
if(d)
s[w] = r-l+;
else
s[w] = ;
lz[w] = d;
return ;
}
pushdown(l,r,w);
int m = (l+r)>>;
if(a<=m)
update(d,a,b,l,m,w<<);
if(b>m)
update(d,a,b,m+,r,w<<|);
pushup(w);
}
int add(int a,int b,int l,int r,int w)
{
if(a<=l&&b>=r)
{
return s[w];
}
pushdown(l,r,w);
int m = (l+r)>>,re=;
if(a<=m)
re+=add(a,b,l,m,w<<);
if(b>m)
re+=add(a,b,m+,r,w<<|);
return re;
}
int main()
{
int t,n,m,k;
//freopen("1004.in","r",stdin);
//freopen("aa.txt","w",stdout);
cin>>t;
while(t--)
{
scanf("%d%d",&n,&m);
build(,n-,);
while(m--)
{
int a,b;
scanf("%d%d%d",&k,&a,&b);
if(k==)
{
int ss;
if(a>)
ss = add(,a-,,n-,);
else ss=;
int x = query(ss+,,n-,);
if(s[]-ss<b)
b = s[]-ss;
int y = query(ss+b,,n-,);
if(ss==s[])
printf("Can not put any one.\n");
else
{printf("%d %d\n",x,y);
update(,x,y,,n-,);
}
}
else
{
int sx = add(a,b,,n-,);
//cout<<sx<<" ,"<<endl; if(b>n-)
b = n-;
printf("%d\n",b-a+-sx);
update(,a,b,,n-,);
}
}
puts("");
}
return ;
}

hdu4614Vases and Flowers的更多相关文章

  1. hdu4614Vases and Flowers(线段树,段设置,更新时范围的右边值为变量)

    Problem Description Alice is so popular that she can receive many flowers everyday. She has N vases ...

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

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

  3. CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)

    Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...

  4. poj 3262 Protecting the Flowers

    http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  5. Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)

    B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...

  6. poj1157LITTLE SHOP OF FLOWERS

    Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...

  7. CF459B Pashmak and Flowers (水

    Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...

  8. 线段树或树状数组---Flowers

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Description As is known to all, the blooming tim ...

  9. sgu 104 Little shop of flowers 解题报告及测试数据

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...

随机推荐

  1. JS基础类型和对象,分别是按值传递还是按引用传递?

    在分析这个问题之前,我们需了解什么是按值传递(call by value),什么是按引用传递(call by reference).在计算机科学里,这个部分叫求值策略(Evaluation Strat ...

  2. [译]GC专家系列1: 理解Java垃圾回收

    原文链接:http://www.cubrid.org/blog/dev-platform/understanding-java-garbage-collection/ 了解Java的垃圾回收(GC)原 ...

  3. laravel扩展Debugbar

    github地址:https://github.com/barryvdh/laravel-debugbar

  4. Treimu更新记录1.2.9.0

    Treimu是一个WPF音乐播放器个人小项目.程序集文件:http://pan.baidu.com/s/1pJLSHsB项目源代码:http://pan.baidu.com/s/1jGHtjfC 1. ...

  5. C#写的SQL聚合函数

    SQL Server 字符串连接聚合函数. 注册程序集: 拷贝“SqlStrConcate.dll”至<sql安装根目录>/MSSQL.1/MSSQL/Binn目录下,执行下面的SQL: ...

  6. 【 socke】C# socket端口复用-多主机头绑定

    什么是端口复用: 因为在winsock的实现中,对于服务器的绑定是可以多重绑定的,在确定多重绑定使用谁的时候,根据一条原则是谁的指定最明确则将包递交给谁,而且没有权限之分.这种多重绑定便称之为端口复用 ...

  7. iOS 基础 第一天(0804)

    OC对象的本质就是一个结构体 为什么说是个结构体? 例如:类里面声明了几个成员变量\实例变量(已添加@plublic),外部对象的指针在访问这个变量的时候是这么写的p->a 0804 注意oc的 ...

  8. Unity3d + UGUI 的多分辨率适配

    原文地址:http://blog.csdn.net/dingkun520wy/article/details/49471789 1.Canvas的属性配置 2.Canvas Scaler的属性配置 3 ...

  9. mybatis foreach标签

    一.批量插入数据 示例:添加订单商品表 1.模型层的相应代码 /** * 添加订单商品表 * @param ordergoods * @return */ public boolean addOrde ...

  10. mac下安装应用及常用快捷键

    从网络上下载的应用程序如何安装? 主要分类为两种:(dmg  和  pkg) 1.dmg类型 此类应用程序安装非常简单,只需要双击图标,然后将此应用程序图标直接拖拽到 application图标上即可 ...