树状数组的区间修改,单点查询

hdu  1556 Color the ball

要想区间修改的话,那么节点就必须往上更新,查询时往上累加。(区间修改,单点查询)

#include
#include
#include
using namespace std;
const int maxn=100000+5;
int C[maxn];
int n;
int lowbit(int x)
{
    return (-x)&x;
}
void update(int x,int y)
{
    for(int i=x; i>0;i-=lowbit(i))
        C[i]+=y;
}
int query(int x)
{
    int s=0;
    for(int k=x; k<=n; k+=lowbit(k))
        s+=C[k];
    return s;
}
int main()                                          
{

    int a,b;
    while(cin>>n)
    {
       for(int i=1; i<=n; i++)
        C[i]=0;
       for(int h=0;h

 

csu 1335 高桥和低桥(树状数组+二分)


#include
#include
#include
#include
using namespace std;
const int N = 1e5+10;
int c[N],m,n,k,a[N];
int x[N],y[N];
int lowbit(int k)
{
    return k&(-k);
}
void add(int k,int he)
{
    while(k>0)
    {
        c[k]+=he;
        k-=lowbit(k);
    }
}

int  Q(int k)
{
    int query=0;
    while(k<=n)
    {
     query+=c[k];
        k+=lowbit(k);
    }
    return query;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.cpp","r",stdin);
    #endif // ONLINE_JUDGE
    int t,from,to,he,kkk=1;
    while(~scanf("%d%d%d",&n,&m,&k))
    {
      memset(c,0,sizeof(c));
      for(int i=0;i=k)
            ans = ans+1;
        }
        printf("Case %d: %d\n",kkk++,ans);
    }
    return 0;
}


相关题:  hdu  A Simple Problem with Integers
                       



你可能感兴趣的:(ACM->数据结构)