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:树状数组第五题~ 死在x=0上,知道为什么错,但是不懂为什么TLE~

Posted by 16310320529 at 2018-02-07 14:57:28 on Problem 2352
In Reply To:树状数组第五题~ 死在x=0上,知道为什么错,但是不懂为什么TLE~ Posted by:snowloving at 2014-08-07 14:37:20
> #include <cstdio>
> #include <cstring>
> #define MAX 32005
> 
> int x[MAX];
> int y[MAX];
> int c[MAX];
> int level[MAX];
> 
> int lowbit(int t)
> {
>     return t&(-t);
> }
> 
> int getSum(int n)
> {
>     int sum=0;
>     while(n>0)
>     {
>         sum+=c[n];
>         n-=lowbit(n);
>     }
>     return sum;
> }
> 
> void Change(int i,int v,int n)
> {
>     while(i<=n)
>     {
>         c[i]+=v;
>         i+=lowbit(i);
>     }
> }
> 
> int main()
> {
>     int n;
>     while(scanf("%d",&n)!=EOF)
>     {
>         memset(level,0,sizeof(level));
>         memset(c,0,sizeof(c));
>         int mx=0;
>         for(int i=1;i<=n;i++)
>         {
>             scanf("%d %d",&x[i],&y[i]);
>             x[i]++;
>             mx=(x[i]>mx)?x[i]:mx;
>         }
>         for(int i=1;i<=n;i++)
>         {
>             Change(x[i],1,mx);
>             int sum=getSum(x[i])-1;
>             level[sum]++;
>         }
>         for(int i=0;i<n;i++)
>         {
>             printf("%d\n",level[i]);
>         }
>         printf("\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