74/100
link is here
according to the question , we should control the direction of update ,it really easy but still hard to think . this time I learn deeper in “the tree”.
And I unconsciously become the first in the number of problem that have been solved among XUPT ‘s students in HDOJ,the website that record my way in NOIP/ICPC .The only achievement I made is that I become more confident than I started.Let we see if I can work continuously to the end!
#include <bits/stdc++.h>
#include <cstring>
#define maxn 200010
using namespace std;
int mn[maxn<<2];
int w;
int update(int l,int r,int v,int root)
{
if(l == r) {mn[root]+=v;return l;}
int m = (l+r)>>1;
int ans;
if(mn[root<<1]+v<=w) ans = update(l,m,v,root<<1);
else ans = update(m+1,r,v,root<<1|1);
mn[root] = min(mn[root<<1],mn[root<<1|1]);
return ans;
}
int main()
{
int h,n,wid;
while(scanf("%d%d%d",&h,&w,&n)!=EOF)
{
memset(mn,0,sizeof(mn));
for(int i=0;i<n;i++)
{
scanf("%d",&wid); //mn[31] is the minimum number
if(mn[1]+wid>w)
{
printf("-1\n");
continue;
}
int ans;
if(h<=200000) ans = update(1,h,wid,1);
else ans = update(1,n,wid,1);
printf("%d\n",ans);
}
}
return 0;
}