hdu-4614 Vases and Flowers 成段更新

题目链接


#include "stdio.h"
#include "string.h"
#include "queue"
#include "vector"
#include "algorithm"
using namespace std;
const int maxn = 50005;
const int mod = 10007;
const int inf = 1<<30;
int n,m;
int op,x,y,fir,las,f;
struct node
{
	int c;
}tree[maxn<<2];
int Pow( int a,int x )
{
	int ans = 1;
	for( int i = 1; i <= x; i ++ )
	{
		ans = ( ans*a )%mod;
	}
	return ans;
}
void PushUp( int rt )
{
	if( tree[rt<<1].c == tree[rt<<1|1].c && tree[rt<<1].c != -1 )
		tree[rt].c = tree[rt<<1].c;
}
void PushDown( int rt )
{
	if( tree[rt].c != -1 )
	{
		tree[rt<<1].c = tree[rt<<1|1].c = tree[rt].c;
		tree[rt].c = -1;
	}
}
void BuildTree( int rt,int ld,int rd )
{
	tree[rt].c = 0;
	if( ld < rd )
	{
		int mid = ( ld+rd )>>1;
		BuildTree( rt<<1,ld,mid );
		BuildTree( rt<<1|1,mid+1,rd );
	}
}
void updata( int rt,int ld,int rd )
{
	if( f <= 0 )	return;
	if( x <= ld && rd <= y && tree[rt].c != -1 && f >= ( rd - ld + 1 ) )
	{
		if( tree[rt].c == 0 ){
			tree[rt].c = 1;
			if( fir == -1 )	fir = ld;
			las = rd;
			f -= rd - ld + 1;
		}
		return;
	}
	PushDown( rt );
	int mid = ( ld+rd )>>1;  
	if( x <= mid )   updata( rt<<1,ld,mid );  
	if( y > mid )    updata( rt<<1|1,mid+1,rd );  
	PushUp( rt );
}
int query( int rt,int ld,int rd )
{
	if( x <= ld && rd <= y && tree[rt].c != -1 )
	{
		if( tree[rt].c == 1 ){
			tree[rt].c = 0;
			return rd - ld + 1;
		}
		else
			return 0;
	}
	if( y < ld || x > rd )	return 0;
	PushDown( rt );
	int mid = ( ld+rd )>>1;  
	int l = query( rt<<1,ld,mid );
	int r = query( rt<<1|1,mid+1,rd );
	PushUp( rt );
	return l + r;
}
int main()
{
	#ifndef ONLINE_JUDGE   
	freopen("data.txt","r",stdin);   
	#endif
	int cas;
	scanf("%d",&cas);
	while( cas -- )
	{
		scanf("%d%d",&n,&m);
		BuildTree( 1,0,n-1 );
		for( int i = 0; i < m; i ++ )
		{
			scanf("%d",&op);
			if( op == 1 )
			{
				scanf("%d%d",&x,&f);
				fir = las = -1;
				y = n-1;
				updata( 1,0,n-1 );
				if( fir == -1 )
					puts("Can not put any one.");
				else
					printf("%d %d\n",fir,las);
			}
			else{
				scanf("%d%d",&x,&y);
				printf("%d\n",query( 1,0,n-1 ));
			}
		}
		puts("");
	}
	return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值