HDU 1166 敵兵布陣

2021-07-11 05:40:56 字數 2475 閱讀 8676

看人家的ac**真的好羨慕啊 我的就是不ac啊 要哭啦
#include #include#includeconst int n = 50000;

struct mtree

tree[n*4+1];

using namespace std;

void build(int node, int b, int e)

int mid = (b+e)>>1;

if(b<=mid)

build(node<<1, b, mid);

if(e>mid)

build(node<<1|1, mid+1, e);

}void update(int node, int b, int e, int add)

int mid = (tree[node].l + tree[node].r)>>1;

if(b <= mid)

update(node<<1, b, e, add);

if(e > mid)

update(node<<1|1, b, e, add);

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

}int question2(int node, int b, int e)

int x = 0;

if(b<=tree[node<<1].r)

x += question2(node<<1, b, e);

if(e>=tree[node<<1|1].l)

x += question2(node<<1|1, b, e);

return x;

}int main()

while(scanf("%s", c))}}

return 0;}/*

1101 2 3 4 5 6 7 8 9 10

query 1 3

add 3 6

query 2 7

sub 10 2

add 6 3

query 3 10

end*/

經過一番奮鬥之後 我的**終於ac啦

#include #include#includestruct mtree

tree[200010];

using namespace std;

void build(int node, int b, int e)

if(b<=mid)

build(node<<1, b, mid);

if(e>mid)

build(node<<1|1, mid+1, e);

}void update(int node, int b, int e, int add)

int mid = (tree[node].l +tree[node].r)>>1;

if(b<=mid)

update(node<<1, b, e, add);

if(e>mid)

update(node<<1|1, b, e, add);

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

}int query(int node, int b, int e)

int x = 0;

if(b<=tree[node<<1].r)

x += query(node<<1, b, e);

if(e>=tree[node<<1|1].l)

x += query(node<<1|1, b, e);

return x;

}int main()

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

while(scanf("%s", c) && strcmp(c,"end")!=0)

else if(strcmp(c,"add")==0)

update(1,l,l,r);

else if(strcmp(c, "sub")==0)

update(1,l,l,-r);}}

return 0;

}

可以借鑑的**~~~~

#include#includeusing namespace std;

#define maxn 50000

struct mtree

tree[maxn*4];

void build(int node,int b,int e)

//右兒子

if(mid=b&&tree[node].e<=e)//查詢空間包括了樹的區間才能取值

int mid=(tree[node].b+tree[node].e)/2;

if(b<=mid)

ans1=query(node*2,b,e);

if(mid

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