poj2759(单点更新)

思路:题目说的是有一个h*w的空板子,然后在上面要粘贴1*w的广告。

广告之间是不能重叠的,然后就是如果没有这个广告的位置了,就输出

-1,有的话就输出贴在第几行。

然后就是线段树维护[L,R]之间的最大宽度,初始宽度w。如果这一

行贴了广告的len[L] -= w[i]。这样分析下来就是线段树的单点更新了QWQ。

/*****************************************
Author      :Crazy_AC(JamesQi)
Time        :2015
File Name   :
*****************************************/
// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
using namespace std;
#define MEM(a,b) memset(a,b,sizeof a)
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> ii;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 20;
#define lson rt << 1
#define rson rt << 1 | 1
int h,w,n;
int len[maxn << 2];
inline void pushup(int rt){
	len[rt] = max(len[lson],len[rson]);
}
void Build(int L,int R,int rt){
	len[rt] = w;
	if (L == R) return;
	int mid = (L + R) >> 1;
	Build(L,mid,lson);
	Build(mid + 1,R,rson);
}
int Query(int L,int R,int rt,int x){
	if (L == R) {
		len[rt] -= x;
		return L;
	}
	int mid = (L + R) >> 1;
	int ret = (len[lson] >= x?Query(L,mid,lson,x):Query(mid + 1,R,rson,x));
	pushup(rt);
	return ret;
}
int main()
{	
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	int x;
	while(~scanf("%d %d %d",&h,&w,&n)){
		h = min(h,n);
		Build(1,h,1);
		for (int i = 1;i <= n;i++){
			scanf("%d",&x);
			if (x > len[1]){
				puts("-1");
				continue;
			}
			printf("%d\n",Query(1,h,1,x));
		}
	}
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值