标签:rest res problem first ble ber eof iostream ons
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> using namespace std; const int MAXN=2e5+5; int h,w,n; struct node { int l,r,maxv; }tree[MAXN<<2]; void pushup(int o) { tree[o].maxv=max(tree[o<<1].maxv,tree[o<<1|1].maxv); } void build(int l,int r,int o) { tree[o].l=l,tree[o].r=r; if(l==r) { tree[o].maxv=w; return; } int mid=(l+r)>>1; build(l,mid,o<<1); build(mid+1,r,o<<1|1); pushup(o); } int query(int val,int o) { int res; if(tree[o].l==tree[o].r) { tree[o].maxv-=val; return tree[o].l; } if(tree[o<<1].maxv<val) res=query(val,o<<1|1); else res=query(val,o<<1); pushup(o); return res; } int main() { while(scanf("%d%d%d",&h,&w,&n)!=EOF) { int t=min(n,h); build(1,t+1,1); for(int i=1;i<=n;i++) { int v; scanf("%d",&v); int res=query(v,1); if(res==t+1) puts("-1"); else printf("%d\n",res); } } return 0; }
标签:rest res problem first ble ber eof iostream ons
原文地址:http://www.cnblogs.com/homura/p/6710477.html