| ||||||||||
| 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:树状数组第五题~ 死在x=0上,知道为什么错,但是不懂为什么TLE~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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator