HDU 1166敵兵布陣

2021-07-07 10:00:13 字數 1022 閱讀 6558

#include#include#includeusing namespace std;

const int treenode = 1<<17;

struct node

node[treenode];

//建樹 , 這個過程中更新的是left和right

void build(int i, int left, int right) //由上向下遞迴建樹

node[i].left = left;

node[i].right = right;

node[i].sum = 0;

int m = (left+right)>>1;

build(i*2, left, m);//左子樹建立

build(i*2+1, m+1, right);//右子樹建立

node[i].sum = node[i<<1].sum+node[i<<1|1].sum;

}//更新樹 //add int p位置 int add修改的值 修改點p

void update(int i, int left, int right, int p, int add) //遞迴

int m = (left+right)>>1;

if(p <= m) update(i*2, left, m, p, add);//更新左子樹

else update(i*2+1, m+1, right, p, add); //更新右子樹

node[i].sum = node[i<<1].sum+node[i<<1|1].sum;

}int query(int i, int ll, int rr, int l, int r) //查詢線段樹

int main()

else if(ch[0] == 'a') update(1, 1, n, a, b);

else if(ch[0] == 's') update(1, 1, n, a, b*-1);} }

return 0;

}

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