這是一道線段樹里最簡單的一類題目了,單點更新型別!
#include #define lson l , m , rt<<1
#define rson m+1 , r , rt<<1|1
const int maxx=55555;
int sum[maxx<<2];
void pushup(int rt)
void build(int l,int r,int rt)
int m=(l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}void update(int p,int add,int l,int r,int rt)
int m=(l+r)>>1;
if(p<=m)update(p,add,lson);
else update(p,add,rson);
pushup(rt);
}int query(int l,int r,int l,int r,int rt)
int m=(l+r)>>1;
int ret=0;
if(l<=m)ret+=query(l,r,lson);
if(r>m)ret+=query(l,r,rson);
return ret;
}int main()
} return 0;
}
hdu 1166 敵兵布陣
線段樹的模版 沒什麼思想 include include include include include include include include include include include include include define ll long long define vi vec...
HDU 1166 敵兵布陣
description lily 特別喜歡養花,但是由於她的花特別多,所以照料這些花就變得不太容易。她把她的花依次排成一行,每盆花都有乙個美觀值。如果lily把某盆花照料的好的話,這盆花的美觀值就會上公升,如果照料的不好的話,這盆花的美觀值就會下降。有時,lily想知道某段連續的花的美觀值之和是多少...
HDU 1166 敵兵布陣
複習線段樹,把notonlysuccess上面的推薦題目都刷一遍。需求 單點更新,區間求和。include include include include include include include include include include include include include ...