标签:source return mis oss paper sts ace roo puts
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 20145 Accepted Submission(s): 8391
#include<bits/stdc++.h> using namespace std; #define N 200005 #define lson i*2, l, m #define rson i*2+1, m+1, r int sum[N*4];///存放节点 int W,H,Q; void pushup(int i) { sum[i]=max(sum[i*2],sum[i*2+1]); } void built(int i,int l,int r) { if(l==r) { sum[i]=W; //cout<<sum[i]<<" "; return; } int m=(l+r)/2; built(lson); built(rson); pushup(i); } int update(int w,int i,int l,int r) { //cout<<"w="<<w<<endl; if(w>sum[i]) { //cout<<"sum[i]="<<sum[i]<<" w="<<w<<endl; return -1; } if(l==r) { //cout<<"l="<<l<<endl; sum[i]-=w; return l; } int m=(l+r)/2; int cur=-1; if(w<=sum[i*2])///优先选上面的位置 cur=update(w,lson); else if(w<=sum[i*2+1])///没有的话选下面的 cur=update(w,rson); pushup(i); return cur; } int main() { //freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin); while(scanf("%d%d%d",&H,&W,&Q)!=EOF) { int n=min(H,Q); built(1,1,n); int op; for(int i=1;i<=Q;i++) { scanf("%d",&op); printf("%d\n",update(op,1,1,n)); } } return 0; }
标签:source return mis oss paper sts ace roo puts
原文地址:http://www.cnblogs.com/wuwangchuxin0924/p/6009431.html