Skip to content

Instantly share code, notes, and snippets.

@chenminhua
Created October 18, 2019 04:03
Show Gist options
  • Save chenminhua/d10ac7347ce531c2688f0cf21b5e4ed5 to your computer and use it in GitHub Desktop.
Save chenminhua/d10ac7347ce531c2688f0cf21b5e4ed5 to your computer and use it in GitHub Desktop.
int a[maxn];
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int y)
{
while(x<=n)
{
a[x]+=y;
x+=lowbit(x);
}
}
int sum(int x)
{
int s=0;
while(x>0)
{
s+=a[x];
x-=lowbit(x);
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment