思路:当k为1的时候,用二分法查询包含有f个空瓶的上界r,然后更新会方便很多,直接更新区间(a,r)了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define lson(x) (x<<1)
#define rson(x) ((x<<1)+1)
#define mid ((tree[po].l+tree[po].r)>>1)
#define inf 1<<30
#define Maxm 1000000
#define Maxn 60000
using namespace std;
struct Tree{
int l,r,left,up;
}tree[Maxm];
int flag=,ans,fir;
void buildTree(int l,int r,int po)
{
tree[po].l=l,tree[po].r=r;
tree[po].left=r-l+;
tree[po].up=;
if(l==r)
return ;
buildTree(l,mid,lson(po));
buildTree(mid+,r,rson(po));
}
void down(int po)
{ if(!tree[po].left)
{
tree[po].up=;
tree[lson(po)].left=;
tree[rson(po)].left=;
tree[rson(po)].up=;
tree[lson(po)].up=;
return ;
}
if(!tree[po].up) return ;
tree[lson(po)].left=mid-tree[po].l+;
tree[rson(po)].left=tree[po].r-mid;
tree[rson(po)].up=;
tree[lson(po)].up=;
tree[po].up=;
}
void update(int l,int r,int po)
{
if(l<=tree[po].l&&r>=tree[po].r)
{
ans+=tree[po].r-tree[po].l+-tree[po].left;
tree[po].left=tree[po].r-tree[po].l+;
tree[po].up=;
return ;
}
down(po);
if(r<=mid)
update(l,r,lson(po));
else
if(l>mid)
update(l,r,rson(po));
else{
update(l,r,lson(po));
update(l,r,rson(po));
}
tree[po].left=tree[lson(po)].left+tree[rson(po)].left;
}
int findTree(int l,int r,int po)
{
if(l<=tree[po].l&&r>=tree[po].r)
{
return tree[po].left;
}
down(po);
int temp=;
if(r<=mid)
temp=findTree(l,r,lson(po));
else
if(l>mid)
temp=findTree(l,r,rson(po));
else{
temp=findTree(l,r,lson(po));
temp+=findTree(l,r,rson(po));
}
tree[po].left=tree[lson(po)].left+tree[rson(po)].left;
return temp;
}
void Insert(int l,int r,int po)
{
if(l<=tree[po].l&&r>=tree[po].r)
{
if(tree[po].left==tree[po].r-tree[po].l+&&!flag)
flag=,fir=tree[po].l;
if(flag)
{
tree[po].left=;
return ;
}
}
if(!tree[po].left)
return ;
down(po);
if(r<=mid)
Insert(l,r,lson(po));
else
if(l>mid)
Insert(l,r,rson(po));
else{
Insert(l,r,lson(po));
Insert(l,r,rson(po));
}
tree[po].left=tree[lson(po)].left+tree[rson(po)].left;
}
int main()
{
int n,m,k,a,b,i,j,t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
buildTree(,n-,);
for(i=;i<=m;i++)
{
scanf("%d%d%d",&k,&a,&b);
if(k==)
{
flag=;
int l,r,Mid,temp;
temp=findTree(a,n-,);
if(temp<b)
b=temp;
l=a,r=n-;
while(r>l)
{
Mid=(l+r)>>;
temp=findTree(a,Mid,);
if(temp>=b)
r=Mid;
else
l=Mid+;
}
Insert(a,r,);
if(!flag)
printf("Can not put any one.\n");
else
printf("%d %d\n",fir,r);
}
else
{
ans=;
update(a,b,);
printf("%d\n",ans);
}
}
printf("\n");
}
return ;
}

最新文章

  1. 常用RGB色值表
  2. X.509证书生成
  3. ISO-8859-1
  4. 【基本计数方法---加法原理和乘法原理】UVa 11538 - Chess Queen
  5. 辛星Spring4.x教程开放下载了
  6. python学习笔记八--动态类型
  7. 阿里云至 Windows Azure 的 Linux 虚拟机迁移
  8. Oracle&amp;#39;s Business Intelligence Applications Configuration Manager 基本概念
  9. .NET踩坑记录【不断更新】
  10. Oracle数据表被drop后的恢复
  11. PDFBox之文档创建
  12. Java IO(Properties/对象序列化/打印流/commons-io)
  13. ui component 是一个前端 mvc 开发框架
  14. JZ2440使用笔记之熟悉uboot和Linux的移植
  15. day5-json和pickle序列化
  16. ZK集群搭建和配置
  17. phpMyAdmin setup.php脚本的任意PHP代码注入漏洞
  18. dev的documentManager,多个tab窗体
  19. 【本周主题】第一期:JavaScript单线程与异步
  20. UNDFTD x Nike Air Max 97 OG Black

热门文章

  1. HDU 4911 Inversion (逆序数 归并排序)
  2. Linux 命令之last命令详解
  3. poj2155 树状数组 Matrix
  4. JQuery Plugin 1 - Simple Plugin
  5. C++中使用union的几点思考(转)
  6. HDU 1498 50 years, 50 colors (行列匹配+最小顶点覆盖)
  7. 为CentOS 加入�本地源
  8. 几种流行Webservice框架性能对照
  9. sublime php语法检查
  10. Metadata Lock原理1