portal:http://codevs.cn/problem/1080/
The question was a little waking up to me: The tree array is not the same as the line tree (half an hour ago the concept of the intellect is silly).
The main idea is to use a tree-like array to store the prefix and then prefix and subtract to get the interval and.
The knowledge of the line segment tree appeared in the Blue Book,,, inexplicably from the Purple book upgrade.
Mark I read that blog: http://blog.csdn.net/dcrusher/article/details/49497395
(This is also very powerful, in three ways)
#include <cstdio>
#include <iostream>
using namespace std;
int tree[999999],n,m;
int lowbit (int x)
{
return x& (-X);
}
int add (int pos,int v)
{
int J;
for (j = pos;j <= n;j + = Lowbit (j))
{
Tree[j] + = v;
}
return 0;
}
int sch (int pos)
{
int ans = 0,j;
for (j = pos;j >= 1;j-= Lowbit (j))
ans + = tree[j];
return ans;
}
int main ()
{
int a,b,c;
scanf ("%d", &n);
for (int i = 1;i <= n;i++)
{
scanf ("%d", &a);
Add (i,a);
}
scanf ("%d", &m);
for (int i = 0;i < m;i++)
{
scanf ("%d%d%d", &a,&b,&c);
Switch (a)
{case
1:
Add (b,c);
break;
Case 2:
int s1,s2;
S1 = Sch (b-1);
S2 = Sch (c);
printf ("%d\n", s2-s1);
break;
}
}
return 0;
}