單點修改單點查詢的線段樹模板題
也可以樹狀陣列做,這裡不詳細介紹。。
我的線段樹做法見**:
#include #include #include #define maxn 50000
int n;
int num[maxn+1];
typedef struct aaa
node;
node *build(int a,int b) //建樹
u->r=b;
u->l=a;
int m=(a+b)>>1;
u->lchild=build(a,m);
u->rchild=build(m+1,b);
u->date=u->lchild->date+u->rchild->date;
return u;
}int qy(int a,int b,node *u) //右孩子查詢
return qy(a,b,u->lchild);
}int qz(int a,int b,node *u) //左孩子查詢
return qz(a,b,u->rchild);
}void qq(int a,int b,node *u) //查詢
int m=(u->l+u->r)>>1;
if(a>m)
else if(b<=m)
else
}void insert(int a,int b,node *u) //修改
int m=(u->l+u->r)>>1;
if(a>m)
insert(a,b,u->rchild);
else
insert(a,b,u->lchild);
}int main()
else if(!strcmp(str,"sub"))
else if(!strcmp(str,"add"))
else
break;}}
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想知道某段連續的花的美觀值之和是多少...