hdu4614Vases and Flowers
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的更多相关文章
- hdu4614Vases and Flowers(线段树,段设置,更新时范围的右边值为变量)
Problem Description Alice is so popular that she can receive many flowers everyday. She has N vases ...
- HDU4614Vases and Flowers 二分+线段树;
参考:https://blog.csdn.net/ophunter_lcm/article/details/9879495 题意: 有n个花瓶,有两种操作,1.从a开始放b朵花,有花的花瓶跳过,2 ...
- CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- 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 ...
- poj1157LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...
- CF459B Pashmak and Flowers (水
Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...
- 线段树或树状数组---Flowers
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Description As is known to all, the blooming tim ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
随机推荐
- php 操作数组 (合并,拆分,追加,查找,删除等)
1. 合并数组 array_merge()函数将数组合并到一起,返回一个联合的数组.所得到的数组以第一个输入数组参数开始,按后面数组参数出现的顺序依次迫加.其形式为: array array_merg ...
- Qt+MinGW+OpenCV开发环境在win7系统下的搭建(最新20140423)
1 搭建环境 (1)联想Y470笔记本电脑,win7操作系统 (2)Qt 5.2.1 Open Source :(Qt Online installer for Window(9MB),即下载页面最上 ...
- 2014年辛星完全解读Javascript第七节 数组和对象
由于Javascript是脚本语言,因此,使用起来非常方便,数组的使用也是比较简单的,下面我们就主要介绍一下Javascript中数组的介绍,以及上一节中没有完成的对象的介绍. *********** ...
- OFBiz进阶之HelloWorld(五)创建新实体
参考文档 https://cwiki.apache.org/confluence/display/OFBIZ/OFBiz+Tutorial+-+A+Beginners+Development+Guid ...
- oracle 绿色版本 instantclient 使用说明
1,将instantclient直接放到D盘根目录 2,注册表修改 3,点击工具>>首选项, 在Oracle主目录名中输入“D:\instantclient_10_2\”,在OCI库中输入 ...
- 内置对象之Cookie
if (!this.IsPostBack) { try { HttpCookie MyCookie = new HttpCookie("MyCookie"); MyCookie.V ...
- 【BZOJ 2005】[Noi2010]能量采集
Description 栋栋有一块长方形的地,他在地上种了一种能量植物,这种植物可以采集太阳光的能量.在这些植物采集能量后,栋栋再使用一个能量汇集机器把这些植物采集到的能量汇集到一起. 栋栋的植物种得 ...
- 【BZOJ3262】 陌上花开
Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当 ...
- jvm 参数调优
FROM: http://www.cnblogs.com/redcreen/archive/2011/05/04/2037057.html#CMSInitiatingOccupancyFraction ...
- 请求管道与IHttpModule接口
IHttpModule向实现类提供模块初始化和处置事件. IHttpModule包含兩個方法: public void Init(HttpApplication context);public vo ...