分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=5e4+;
int n,m,T,c[N<<],lz[N<<];
void build(int rt,int l,int r){
lz[rt]=-;
if(l==r){c[rt]=;return;}
int m=(l+r)>>;
build(rt<<,l,m);
build(rt<<|,m+,r);
c[rt]=c[rt<<]+c[rt<<|];
}
void pushdown(int rt,int l,int r){
if(lz[rt]!=-){
int m=(l+r)>>;
c[rt<<]=lz[rt]*(m-l+);
c[rt<<|]=lz[rt]*(r-m);
lz[rt<<]=lz[rt<<|]=lz[rt];
lz[rt]=-;
}
}
int t;
void modify(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y){
c[rt]=t*(r-l+);
lz[rt]=t;
return;
}
int m=(l+r)>>;
pushdown(rt,l,r);
if(x<=m)modify(rt<<,l,m,x,y);
if(y>m)modify(rt<<|,m+,r,x,y);
c[rt]=c[rt<<]+c[rt<<|];
}
int ask(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y)return c[rt];
int m=(l+r)>>,ans=;
pushdown(rt,l,r);
if(x<=m)ans+=ask(rt<<,l,m,x,y);
if(y>m)ans+=ask(rt<<|,m+,r,x,y);
return ans;
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
build(,,n);
while(m--){
int op,x,y;
scanf("%d%d%d",&op,&x,&y);
if(op==){
++x,++y;
printf("%d\n",y-x+-ask(,,n,x,y));
t=;modify(,,n,x,y);
continue;
}
++x;
y=min(y,ask(,,n,x,n));
if(!y){
printf("Can not put any one.\n");
continue;
}
int ans1,ans2;
int l=x,r=n;
while(l<r){
int mid=(l+r)>>,cur=ask(,,n,x,mid);
if(!cur)l=mid+;
else r=mid;
}
ans1=(l+r)>>;
l=x,r=n;
while(l<r){
int mid=(l+r)>>,cur=ask(,,n,x,mid);
if(cur<y)l=mid+;
else r=mid;
}
ans2=(l+r)>>;
t=;modify(,,n,ans1,ans2);
printf("%d %d\n",--ans1,--ans2);
}
printf("\n");
}
return ;
}