hdu2795 Billboard 线段树区间更新

来源:互联网 发布:mac关闭日历广告 编辑:程序博客网 时间:2024/06/13 07:10

简单区间统计

#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;#define maxn 210000#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1int tree[maxn<<2];int h,w,n;void pushup(int rt){    tree[rt]=max(tree[rt<<1],tree[rt<<1|1]);}void build(int l,int r,int rt){    tree[rt]=w;    if(l==r)    {        return;    }    int m=(l+r)>>1;    build(lson);    build(rson);}int query(int x,int l,int r,int rt){    int tmp;    if(l==r)    {        tree[rt]-=x;        return l;    }    int m=(l+r)>>1;    if(tree[rt<<1]>=x)    {        tmp=query(x,lson);    }    else    {        tmp=query(x,rson);    }    pushup(rt);    return tmp;}int main(){    while (~scanf("%d%d%d",&h,&w,&n))    {if (h > n) h = n;build(1 , h , 1);while (n --){int x;scanf("%d",&x);if (tree[1] < x) puts("-1");else printf("%d\n",query(x , 1 , h , 1));}}    return 0;}


0 0