标签:意义 add 简单 mes pac code pre register scanf
c1=a1;
c2=a1+a2;
c3=a3;
c4=a1+a2+a3+a4;
c0001=a0001
c0010=a0001+a0010
c0011=a0011
c0100=a0001+a0010+a0011+a0100
inline int lowbit(register int x)
{
return x&(-x);
}
inline void add(register int x,register int k)
{
while(x<=n)
{
tree[x]+=k;
x+=lowbit(x);
}
}
ans+=c[0111];
ans+=c[0111-0001(0110)];
ans+=c[0110-0010(0100)];
ans+=c[0100-0100(c[0]无意义,结束)]
inline int sum(register int x)
{
int ans=0;
while(x!=0)
{
ans+=tree[x];
x-=lowbit(x);
}
return ans;
}
#include <bits/stdc++.h>
using namespace std;
int n,m,tree[2000010];
inline int lowbit(register int x)
{
return x&(-x);
}
inline void add(register int x,register int k)
{
while(x<=n)
{
tree[x]+=k;
x+=lowbit(x);
}
}
inline int sum(register int x)
{
int ans=0;
while(x!=0)
{
ans+=tree[x];
x-=lowbit(x);
}
return ans;
}
int main()
{
scanf("%d%d",&n,&m);
for(register int i=1;i<=n;++i)
{
int a;
scanf("%d",&a);
add(i,a);
}
while(m--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a==1)
add(b,c);
else
printf("%d\n",sum(c)-sum(b-1));
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int n,m;
int input[500010];
int tree[500100];
inline int lowbit(register int x)
{
return x&(-x);
}
inline void add(register int x,register int k)
{
while(x<=n)
{
tree[x]+=k;
x+=lowbit(x);
}
}
inline int search(register int x)
{
int ans=0;
while(x!=0)
{
ans+=tree[x];
x-=lowbit(x);
}
return ans;
}
int main()
{
scanf("%d%d",&n,&m);
for(register int i=1;i<=n;++i)
scanf("%d",&input[i]);
while(m--)
{
int a;
scanf("%d",&a);
if(a==1)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
add(x,z);
add(y+1,-z);
}
else
{
int x;
scanf("%d",&x);
printf("%d\n",input[x]+search(x));
}
}
}
标签:意义 add 简单 mes pac code pre register scanf
原文地址:https://www.cnblogs.com/yzhang-rp-inf/p/10073405.html