标签:top log 级别 accept c++ ret content update memory
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 23498 Accepted Submission(s): 9687
1 #include<bits/stdc++.h> 2 using namespace std; 3 int maxn[(200000<<2)+20]; 4 int H,N,W,X; 5 void build() 6 { 7 int M=X<<2; 8 for(int i=1;i<=M;++i) maxn[i]=W; 9 } 10 void update(int L,int R,int id,int tar,int x) 11 { 12 int m=(L+R)>>1,lc=id<<1,rc=(id<<1)|1; 13 if(L==R&&L==tar) {maxn[id]=x;return;} 14 if(tar<=m){ 15 update(L,m,lc,tar,x); 16 } 17 else{ 18 update(m+1,R,rc,tar,x); 19 } 20 maxn[id]=max(maxn[lc],maxn[rc]); 21 } 22 int ask(int L,int R,int id,int x) 23 { 24 if(maxn[id]<x) return -1; 25 if(L==R) {update(1,X,1,L,maxn[id]-x);return L;} 26 int m=(L+R)>>1,lc=id<<1,rc=(id<<1)|1; 27 if(maxn[lc]>=x){ 28 return ask(L,m,lc,x); 29 } 30 else{ 31 return ask(m+1,R,rc,x); 32 } 33 } 34 int main() 35 { 36 int i,j,k,wi; 37 while(cin>>H>>W>>N){X=min(H,N); 38 build(); 39 for(i=1;i<=N;++i){ 40 scanf("%d",&wi); 41 printf("%d\n",ask(1,X,1,wi)); 42 } 43 } 44 return 0; 45 }
标签:top log 级别 accept c++ ret content update memory
原文地址:http://www.cnblogs.com/zzqc/p/7260693.html