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 gnaggnoyil at 2009-12-27 16:56:44 on Problem 2481
In Reply To:这个题目测试有问题没? Posted by:venushjx at 2009-12-04 14:45:47
我的程序也是0 0 2 2,就没问题,AC了.
LZ你找的【AC程序】估计是错的吧
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#define maxn 100005
#define lowbit(x) ((x)&(-(x)))
#define max(a,b) (((a)>(b))?(a):(b))
#define randomize srand((int)time(NULL))
#define random(a) (rand()%(a))
#define clr(a) memset(a,0,sizeof(a))
#define init clr(c),clr(l),clr(r),clr(num),clr(ans),m=0
int c[maxn],l[maxn],r[maxn],num[maxn],ans[maxn];
int n,m;
int modify(int x,int k){
  for(int i=x;i<=m;c[i]+=k,i+=lowbit(i));
  return 0;
}
int query(int x){
  int ans=0;
  for(int i=x;i>0;ans+=c[i],i-=lowbit(i));
  return ans;
}
int swap(int &a,int &b){
  int c=a;
  return a=b,b=c,0;
}
int qsort(int m,int n){
  if((m+1==n)&&((r[m]<r[n])||((r[m]==r[n])&&(l[m]>l[n]))))
    return swap(l[m],l[n]),swap(r[m],r[n]),swap(num[m],num[n]);
  if(m<n){
    int i=m-1,j=random(n-m)+m;
    swap(l[j],l[n]),swap(r[j],r[n]),swap(num[j],num[n]);
    for(j=m;j<n;j++)
      if((r[j]>r[n])||((r[j]==r[n])&&(l[j]<l[n])))
        swap(l[++i],l[j]),swap(r[i],r[j]),swap(num[i],num[j]);
    swap(l[i+1],l[n]),swap(r[i+1],r[n]),swap(num[i+1],num[n]);
    return qsort(m,i),qsort(i+2,n),0;
  }
}
int main(){
  for(randomize;scanf("%d",&n),n!=0;init){
    for(int i=1;i<=n;i++)
      scanf("%d%d",&l[i],&r[i]),l[i]++,r[i]++,num[i]=i,m=max(m,r[i]);
    qsort(1,n);
    ans[num[1]]=0;
    modify(l[1],1);
    for(int i=2;i<=n;i++){
      if((l[i-1]==l[i])&&(r[i-1]==r[i]))
        ans[num[i]]=ans[num[i-1]];
      else
        ans[num[i]]=query(l[i]);
      modify(l[i],1);
    }
    for(int i=1;i<n;i++)
      printf("%d ",ans[i]);
    printf("%d\n",ans[n]);
  }
  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