HDU 1166 敵兵布陣

2021-07-04 16:06:11 字數 716 閱讀 5063

題意:給出乙個n個數字,進行2種操作,更改乙個數字大小或者詢問乙個區間所有數字的和

思路:線段樹典型的單點更新,區間詢問,用樹狀陣列也可以實現,s陣列要從1開始,一時沒注意查了好久

#include #include #include #include #define maxn 500030

using namespace std;

struct tree

tree[maxn*3];

int s[maxn];

char op[10];

void build(int root,int l,int r)

int mid=(l+r)>>1;

build(root<<1,l,mid);

build(root<<1|1,mid+1,r);

tree[root].date=tree[root<<1].date+tree[root<<1|1].date;

}void update(int root,int p,int val)

return;

}int que(int root,int l,int r)

int main()

build(1,1,n);

printf("case %d:\n",++cas);

while (scanf("%s",&op) && op[0]!='e')

}}

hdu 1166 敵兵布陣

這是一道線段樹里最簡單的一類題目了,單點更新型別!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...

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想知道某段連續的花的美觀值之和是多少...