# 秋实大哥与线段树

##### Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)

“学习本无底，前进莫徬徨。” 秋实大哥对一旁玩手机的学弟说道。

## Input

1 x v : 表示将第x个元素的值改为v
2 l r : 表示询问[l,r]这个区间的元素和

1nmvai1000001lrn

## Sample input and output

Sample Input Sample Output
3
1 2 3
3
2 1 2
1 1 5
2 1 2
3
7

## Source

2015 UESTC Training for Data Structures

void update(int mi,int pos,int v,int rt)
{
if(tree[rt].lc==tree[rt].rc&&tree[rt].lc==pos)
{
tree[rt].sum=v;
return ;
}
int mid=(tree[rt].lc+tree[rt].rc)>>1;
if(pos<=mid)update(mid,pos,v,rt<<1);
else update(mid,pos,v,rt<<1|1);
pushup(rt);
}

#include<iostream>
#include<cstdio>
using namespace std;
#define N 100005
#define LL long long
struct point
{
int lc,rc;
LL sum;
}tree[N<<2];
LL sumr;
void pushup(int rt)
{
tree[rt].sum=tree[(rt<<1)].sum+tree[(rt<<1|1)].sum;
}
void build(int L,int R,int rt)
{
tree[rt].lc=L;
tree[rt].rc=R;
if(L==R)
{
scanf("%lld",&tree[rt].sum);
return ;
}
int mid=(L+R)>>1;
build(L,mid,rt<<1);
build(mid+1,R,rt<<1|1);
pushup(rt);
}
void update(int pos,int v,int rt)
{
if(tree[rt].lc==tree[rt].rc&&tree[rt].lc==pos)
{
tree[rt].sum=v;
return ;
}
int mid=(tree[rt].lc+tree[rt].rc)>>1;
if(pos<=mid)update(pos,v,rt<<1);
else update(pos,v,rt<<1|1);
pushup(rt);
}
void query(int L,int R,int rt)
{
if(L==tree[rt].lc&&R==tree[rt].rc)
{
sumr+=tree[rt].sum;
return ;
}
int mid=(tree[rt].lc+tree[rt].rc)>>1;
if(R<=mid)query(L,R,rt<<1);
else if (L>mid)query(L,R,rt<<1|1);
else
{
query(L,mid,rt<<1);
query(mid+1,R,rt<<1|1);
}
}
int main()
{
#ifdef CDZSC
freopen("i.txt","r",stdin);
#endif
int n,m,x,y,k;
while(~scanf("%d",&n))
{
build(1,n,1);
scanf("%d",&m);
while(m--)
{
scanf("%d%d%d",&k,&x,&y);
if(k==1)
{
update(x,y,1);
}
else
{
sumr=0;
query(x,y,1);
printf("%lld\n",sumr);
}
}
}
return 0;
}

#### UESTC 1073

2018-02-02 11:13:32

#### The 15th UESTC Programming Contest Final 总结

2017-04-04 09:58:02

#### 【UESTC】2015 UESTC Training for Data Structures

2015-12-17 00:30:18

#### hdu5475__An easy problem(线段树单点更新)

2015-09-28 20:02:01

#### 树状数组的单点更新，区间查询。

2017-07-21 17:05:11

#### 秋实大哥与线段树 UESTC - 1073

2017-06-18 01:02:26

#### 2014 UESTC Training for Dynamic Programming

2014-06-02 12:00:15

#### 杭电acm1073

2015-12-08 13:11:50

#### 51nod 1073约瑟夫环问题、

2016-09-05 19:50:38

#### The 14th UESTC Programming Contest Final Warmup D - Cube

2016-04-03 12:31:40

UESTC 1073 单点更新