标签:
Description
Input
Output
Sample Input
Sample Output
# include<cstdio> # include<iostream> using namespace std; int h,w,n; # define MAX 200004 # define lid id<<1 # define rid id<<1|1 struct Segtree { int l,r; int mx; }tree[MAX*4]; void push_up ( int id ) { tree[id].mx=max(tree[lid].mx,tree[rid].mx); } void build( int id,int l,int r ) { tree[id].l = l; tree[id].r = r; tree[id].mx = w; if ( l==r ) { return; } int mid = ( tree[id].l+tree[id].r )/2; build(lid,l,mid); build(rid,mid+1,r); push_up(id); } int query( int id,int val ) { if ( tree[id].l==tree[id].r ) { tree[id].mx-=val; return tree[id].l; } int pos = 0; if ( tree[lid].mx >= val ) pos = query(lid,val); else pos = query(rid,val); push_up(id); return pos; } int main(void) { while ( scanf("%d%d%d",&h,&w,&n)!=EOF ) { if ( h > MAX ) h = MAX; build(1,1,h); for ( int i = 0;i < n;i++ ) { int tmp; scanf("%d",&tmp); if ( tree[1].mx < tmp ) printf("-1\n"); else { int ans = query(1,tmp); printf("%d\n",ans); } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/wikioibai/p/4741766.html