题目传送门:http://codeforces.com/gym/100623/attachments
题解:这道题吧,队友做的,听他说是线段树基础题...
Code:
#include <bits/stdc++.h>
using namespace std;
#define ls l,mid,rt*2
#define rs mid+1,r,rt*2+1
#define mi (l+r)>>1
const int MAXN=200000+100;
int n,m,k,tree[MAXN*4],v,pos,t;
void push_up(int rt){
tree[rt]=max(tree[rt*2+1],tree[rt*2]);
return ;
}
void build(int l,int r,int rt,int val){
if(l==r){
tree[rt]=val;
//cout<<val<<' '<<rt<<' '<<tree[rt]<<endl;
return ;
}
int mid=mi;
build(ls,val);
build(rs,val);
push_up(rt);
return ;
}
void query(int l,int r,int rt){
if(tree[rt]<v||pos!=-1) return ;
if(l==r){
tree[rt]-=v;
pos=l;
return ;
}
int mid=mi;
query(ls);
query(rs);
push_up(rt);
return ;
}
int main(){
freopen("billboard.in","r",stdin);
freopen("billboard.out","w",stdout);
int n,m,k;
while(scanf("%d%d%d",&n,&m,&t)!=-1){
n=min(200000,n);
build(1,n,1,m);
for(int i=0;i<t;i++){
pos=-1;
scanf("%d",&v);
if(v<=m) query(1,n,1);
printf("%d\n",pos);
}
}
}