hdu1166 敵兵布陣 (線段樹)

2021-08-10 01:29:53 字數 855 閱讀 6587

用到了 線段樹 ,好厲害的題

這裡要用 scanf 而不是 cin ,不然會超時的。

參考:

#include #include using namespace std;

int amount[200000];

/* l和r表示線段樹中該結點的左端點和右端點

root是當前線段樹根結點的編號

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

mid=(l+r)/2;

build(l,mid,2*root); //遞迴構造左子樹

build(mid+1,r,2*root+1); //遞迴構造右子樹

amount[root]=amount[2*root]+amount[2*root+1];}/*

i~j是查詢範圍,

*/int query(int i,int j,int left,int right,int root)

void updata(int l,int r,int root,int i,int value)

mid=(l+r)/2;

if(i<=mid)

updata(l,mid,2*root,i,value);

else

updata(mid+1,r,2*root+1,i,value);

amount[root]=amount[2*root]+amount[2*root+1];

}int main()

else if(str[0]=='s')

else

printf("%d\n",query(i,j,1,n,1));}}

return 0;

}

HDU 1166 敵兵布陣 線段樹

第一道線段樹的題目,正在學習中 include include include using namespace std define max 55555 int sum max 2 n void pushup int rt void build int l,int r,int rt int mid ...

hdu1166敵兵布陣 線段樹

problem description c國的死對頭a國這段時間正在進行軍事演習,所以c國間諜頭子derek和他手下tidy又開始忙乎了。a國在海岸線沿直線布置了n個工兵營地,derek和tidy的任務就是要監視這些工兵營地的活動情況。由於採取了某種先進的監測手段,所以每個工兵營地的人數c國都掌握的...

A 敵兵布陣 線段樹 hdu 1166

a 敵兵布陣 time limit 1000ms memory limit 32768kb 64bit io format i64d i64u submit status practice hdu 1166 description c國的死對頭a國這段時間正在進行軍事演習,所以c國間諜頭子derek...