线段树、树状数组入门
HDU-1166 思路:更新区间,结构体内保存最大值 1 #include<stdio.h> 2 #include<string> 3 #include<iostream> 4 using namespace std; 5 const int MAXN = 5e4+5; 6 int a[MAXN]; 7 struct node 8 { 9 int L,R,sum,la; 10 }tree[MAXN<<2]; 11 //建树 12 void Build(int L,int R,int step) 13 { 14 tree[step].L=L;tree[step].R=R; 15 if(L==R) 16 { 17 tree[step].sum=a[L];return; 18 } 19 int mid=(L+R)>>1; 20 Build(L,mid,step<<1); 21 Build(mid+1,R,step<<1|1); 22 tree[step].sum=tree[step<<1].sum+tree[step<<1|1].sum; 23 } 24 //单点查询 25 int Query(int P,int step) 26 { 27 if(tree[step].L==tree[step].R)return tree[step].sum; 28 int mid=(tree[step