hdu 1166 敵兵布陣 區間和

2021-07-25 08:48:14 字數 1145 閱讀 8413

problem:

給n個節點,有很多命令,兩種命令,一種是更新節點的值,一種是區間求和:

solution:

利用線段樹堆區間求和

note:

要關閉cin的同步,不然會超時。

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using

namespace

std;

#define ms(s) memset(s,0,sizeof(s))

typedef

unsigned

long

long ull;

typedef

long

long ll;

const

double pi = 3.141592653589;

const

int inf = 0x3fffffff;

#define maxn 50000

struct node

};node tree[maxn*4];

int value[maxn+10];

int flag;

//初始化樹,根節點是1

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

}//查詢和

int query_tree(int root, int l, int r)

}void update_tree(int root, int idx, int v)

}int main()

else

if(s == "sub")

else

if(s == "query")

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