#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=1e5+10;
int p[N],tree[N];
void creat(int node,int start,int end)
{
if(start==end) tree[node]=p[start];
int mid=(start+end)/2;
int left=node*2;
int right=node*2+1;
creat(left,start,mid);
creat(right,mid+1,end);
tree[node]=tree[right]+tree[left];
}
void update(int node,int start,int end,int x,int val)
{
if(start==end)
{
p[x]=val;
tree[node]=val;
}
int mid=(start+end)/2;
int left=node*2;
int right=node*2+1;
if(x>=start&&x<=mid) update(left,start,mid,x,val);
else update(right,mid+1,end,x,val);
tree[node]=tree[right]+tree[left];
}
int query(int node,int start,int end,int L,int R)
{
if(start>R||end<L) return 0;
else if(start>=L&&end<=R) return tree[node];
else{
int mid=(end+start)/2;
int right=node*2+1;
int left=node*2;
int sum_left=query(left,start,mid,L,R);
int sum_right=query(right,mid+1,end,L,R;)
return sum_left+sum_right;
}
}
int main ()
{
int n;
scanf("%d",&n);
for(int i=0;i<=n;i++) cin>>p[i];
creat(1,1,n);
return 0;
}
用线段树的时候,tree数组开4倍