Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

帮忙看看为什么RE?

Posted by super_miker at 2009-05-03 11:48:30 on Problem 2104
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator