题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795
好吧,写了这么多单点更新的题目,这样的就很简单了,不过我第一次用这样的风格写代码;向这种简短风格靠齐;
不过题目给的数据感觉还挺坑的,还好我机智的看了Discuss。。。。哈哈,仰天长笑。。。。
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#define LL long long
#define inf 1<<30
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
const int N=250005;
int Max[N<<2]; // 用来存各个节点的最大长度;
int h,w,n;
void PushUp(int rt)
{
Max[rt]=max(Max[rt<<1],Max[rt<<1|1]);
}
void build(int l,int r,int rt)
{
Max[rt]=w;
if(l==r) return;
int mid=(l+r)>>1;
build(lson);
build(rson);
}
int query(int x,int l,int r,int rt)
{
if(l==r){
Max[rt]-=x;
return l;
}
int mid=(l+r)>>1;
int ans=0;
if(Max[rt<<1]>=x) ans=query(x,lson);
else ans=query(x,rson);
PushUp(rt);
return ans;
}
int main()
{
while(~scanf("%d%d%d",&h,&w,&n)){
if(h>n) h=n; // 这一条语句绝对不能少,虽然告诉你有10^9行,但是,我只有n张海报,所以最多有n行就够了,没有意思到这一点的话肯定会RE的;
build(1,h,1);
for(int i=0;i<n;i++){
int x;
scanf("%d",&x);
if(Max[1]<x) printf("-1\n");
else printf("%d\n",query(x,1,h,1));
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/wlxsq/article/details/47145833