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 问题: 你想要将你的 ...
随机推荐
- RHEL 6.5升级GCC 4.9.3
前提:保证旧版的gcc,g++存在! root用户 1. 下载源码和依赖包源码:新建目录bakwget http://ftp.gnu.org/gnu/gcc/gcc-4.9.3/gcc-4.9.3.t ...
- php学习日志(2)-php变量
变量是用于存储数据的容器,与代数相似,可以给变量赋予某个确定的值(例如:$x=3)或者是赋予其它的变量(例如:$x=$y+$z).变量的定义主要有以下规则: 变量以$开始,后面跟着变量的名称: 变量名 ...
- Spark Streaming揭秘 Day6 关于SparkStreaming Job的一些思考
Spark Streaming揭秘 Day6 关于SparkStreaming Job的一些思考 Job是SparkStreaming的重要基础,今天让我们深入,进行一些思考. Job是什么? 首先, ...
- C语言宏定义取得两数的最大值和最小值
/*本程序时为了验证用宏来做 * 两个数的大小比较的写法*/#include<stdio.h>#define MAX(x,y) ((x)<(y)?(y):(x))#define MI ...
- python中执行javascript代码
python中执行javascript代码: 1.安装相应的库,我使用的是PyV8 2.import PyV8 ctxt = PyV8.JSContext() ctxt.enter() ...
- CSS溢出文本省略(text-overflow)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 特定用户QQ群聊天记录导出的实现
一.把QQ群的聊天记录txt格式导出 消息管理器 -> 选择要导出的群 -> 右击.导出 这里要注意 : 导出之后的 文本是 unicode 编码的,需要转换 ==|| 之前不知道,搞 ...
- tableView的基本使用(改良版)
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate> { int i;//用来计算接受通知的次数 ...
- Linux计算机进程地址空间与内核装载ELF
本文基于Linux™系统对进程创建与加载进行分析,文中实现了Linux库函数fork.exec,剖析内核态执行过程,并进一步展示进程创建过程中进程控制块字段变化信息及ELF文件加载过程. 一.初识Li ...
- springMVC从上传的Excel文件中读取数据
示例:导入客户文件(Excle文件) 一.编辑customer.xlsx 二.在spring的xml文件设置上传文件大小 <!-- 上传文件拦截,设置最大上传文件大小 10M=10*1024*1 ...