Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
帮忙看看为什么RE?#include<stdio.h> #include<stdlib.h> long *head[100001]; long arr[100001]; long sort[100001]; long size[100001]; long tmp[100001]; long n,m; long getlow(long t){ return (t&(-t)); } long getsize(long t){ if(t+getlow(t)<=n)return getlow(t); else return n-t+1; } void msort(int b,int e){ if(b<e){ long mid=(b+e)/2; long i=b,j=mid+1,k=b; msort(b,mid); msort(mid+1,e); while(i<=mid&&j<=e){ if(arr[sort[i]]<arr[sort[j]]){ tmp[k++]=sort[i++]; }else{ tmp[k++]=sort[j++]; } } while(i<=mid){ tmp[k++]=sort[i++]; } while(j<=e){ tmp[k++]=sort[j++]; } for(i=b;i<=e;i++){ sort[i]=tmp[i]; } } } void insert(int j,int pj){ while(j<=n){ head[j][size[j]++]=pj; j=j+getlow(j); } } long search3(int i,int j){ long l=0,h=size[i],mid; while(l<h){ mid=(l+h)/2; if(head[i][mid]>j)h=mid; else l=mid+1; } return l; } long search2(int i,int j){ long s=0; while(i){ s+=search3(i,j); i-=getlow(i); } return s; } long search(int i,int j,int k){ long l=1,h=n,mid; while(l<h){ mid=(l+h)/2; if(search2(j,mid)-search2(i-1,mid)>=k)h=mid; else l=mid+1; } return l; } int main(){ long i,j,k; scanf("%ld %ld",&n,&m); for(i=1;i<=n;i++){ scanf("%ld",&arr[i]); sort[i]=i; head[i]=(long*)malloc(getsize(i)*sizeof(long)); } msort(1,n); for(i=1;i<=n;i++){ insert(sort[i],i); } while(m--){ scanf("%ld%ld%ld",&i,&j,&k); printf("%ld\n",arr[sort[search(i,j,k)]]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator