###### HDU 4027 Can you answer these queries? 线段树

ACcode:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define maxn 100002
#define ll long long
#define inf 0x3f3f3f3f
#define mid ((l+r)>>1)
#define tmp (st<<1)
#define len (r-l+1)
#define lson l,mid,tmp
#define rson mid+1,r,tmp|1
#define push_up(x) sum[x]=sum[tmp]+sum[tmp|1]
using namespace std;
ll sum[maxn<<2];
inline void build(int l,int r,int st){
sum[st]=0;
if(l==r){
scanf("%I64d",&sum[st]);
return ;
}
build(lson);
build(rson);
push_up(st);
}
inline void updata(int L,int R,int l,int r,int st){
if(sum[st]==r-l+1)return;
if(l==r){
sum[st]=sqrt(double(sum[st]));
return ;
}
if(L<=mid)updata(L,R,lson);
if(R>mid)updata(L,R,rson);
push_up(st);
}
inline ll query(int L,int R,int l,int r,int st){
if(L<=l&&r<=R)return sum[st];
ll ret=0;
if(L<=mid)ret+=query(L,R,lson);
if(R>mid)ret+=query(L,R,rson);
return ret;
}
int main(){
int cnt=1,n,q;
while(~scanf("%d",&n)){
build(1,n,1);
scanf("%d",&q);
printf("Case #%d:\n",cnt++);
while(q--){
int k,x,y;
scanf("%d%d%d",&k,&x,&y);
if(x>y)x^=y^=x^=y;
if(k)printf("%I64d\n",query(x,y,1,n,1));
else updata(x,y,1,n,1);
}
putchar('\n');
}
return 0;
}


#### HDU4027：Can you answer these queries?(线段树单点更新)

2013-11-10 15:42:08

#### SPOJ 1557. Can you answer these queries II (很强的线段树）

2013-01-03 20:07:32

#### SPOJ GSS5 Can you answer these queries V （线段树）

2014-05-18 00:09:34

#### SPOJ GSS7 Can you answer these queries VII

2015-04-09 19:27:15

#### kuangbin——线段树专题 G - Can you answer these queries?

2016-08-05 14:44:46

#### SPOJ-GSS7 Can you answer these queries VII(树上区间最大和)

2017-01-28 21:15:22

#### SPOJ GSS2 Can you answer these queries II

2015-04-09 19:00:08

#### SPOJ 1043 Can you answer these queries I（GSS1 线段树）

2012-09-15 16:23:08

#### GSS5 - Can you answer these queries V

2016-09-09 17:35:19

#### [SPOJ GSS2] Can you answer these queries II [线段树]

2014-07-27 10:31:01

## 不良信息举报

HDU 4027 Can you answer these queries? 线段树