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. php header函数要点

    发布:snowfly   来源:网络     [大 中 小] 相信很多人写程序时,使用 header(location) 进行跳转往往不记得写 exit() 语句,这种做法存在严重风险. 从浏览器来看 ...

  2. php curl抓取远程页面内容的代码

    使用php curl抓取远程页面内容的例子. 代码如下: <?php /** * php curl抓取远程网页内容 * edit by www.jbxue.com */ $curlPost = ...

  3. git命令行

    cmd下运行或者 进入git bash运行 输入 exit退出切换到仓库目录后再git statusgit commit -m 注释 git pull origin1 mastergit push o ...

  4. Android类库常用类库一览

    在Android SDK中包括很多包文件,通过了解这些包的功能也有助于了解可以开发的功能. 在Android类库中,各种包写成android.*的方式,重要包的描述如下所示: android.app ...

  5. 转 在无法通过yum下载非标准包时,怎么办

    在CentOS下,我们可以通过yum来下载或更新rpm包,但是标准的源(repository)里只提供一部分的rpm包,虽然大部分情况下,这些包是够用的.但是有时候还是需要下载其他的一些非标准的包,如 ...

  6. 1065. A+B and C (64bit)

    #include<stdio.h> #include <math.h> int main() { long long a,b,c,sum; int n,i; while(sca ...

  7. 每日一记:搭建Memcached + php 缓存系统

    服务器环境,Centos6.5 1.安装Memcached服务端 Yum -y install memcached 2.配置Memcached服务端用户以及自动启动服务等 将服务配置成自启动 chkc ...

  8. 如何在Linux下重命名多个文件

    在Linux中,当你想要改变一个文件名,使用mv命令就好了.然而mv不能使用通配符重命名多个文件.可以用sed.awk或者与xargs结合使用来处理多个文件的情况.然而,这些命令行即繁琐又不友好,并且 ...

  9. Nhibernate 一对一关系映射(主键映射)

    参考:点击这里 妈的,搞了一天了,终于可以了,现在总结下,以防下次再出现这样痛苦的问题了,有两个表:user(用户)和Blog(设置表),它们之间的关系正如我所说的是一对一的关系.现在我们来映射这两个 ...

  10. 使用Pod集成Bugtags填坑记

    最近某朋友的朋友的创业公司新出了一个工具叫Bugtags,说是可以让APP测试变得so easy,于是动手来做1.1.0的版本集成,先把WEB首页贴在下面,感兴趣的同学可以去look一下:https: ...