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

树状数组不解释,注意0&0会死循环

Posted by 2017401349fei at 2018-09-28 22:05:42 on Problem 2352
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
const int maxn=3e4+2010;
int a[15000+10],c[maxn];
int lowbit(int x)
{
    return x&(-x);
}
void update(int x)
{
    while(x<=maxn)
    {
        c[x]+=1;
        x+=lowbit(x);
    }
}
int sum(int x)
{
    int sum1=0;
    while(x>0)
    {
        sum1+=c[x];
        x-=lowbit(x);
    }
    return sum1;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(c,0,sizeof(c));
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++)
        {
            int x,y;
            scanf("%d %d",&x,&y);
            int num=sum(x+1);
            a[num+1]++;
            update(x+1);
        }
        for(int i=1;i<=n;i++)
            printf("%d\n",a[i]);
    }
    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