点击打开链接
题意:弱校的OJ的弱题,给定一棵树,和关系,然后在节点上更新时,它的所有儿子也要更新,有个判断条件,查询是所有节点的值的和
思路:与HDU 5692一样的思路,不多说了
#pragma comment(linker, "/STACK:102400000, 102400000")
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int maxn=100010;
vectorG[maxn];
ll num[maxn*4],lazy[maxn*4],min1[maxn*4];
int L[maxn],R[maxn];
int idx;
void dfs(int u,int f){
L[u]=++idx;
for(unsigned int i=0;i>1));
num[node<<1|1]+=lazy[node]*(ll)(m>>1);
min1[node<<1]+=lazy[node];
min1[node<<1|1]+=lazy[node];
lazy[node]=0;
}
}
void buildtree(int le,int ri,int node){
if(le==ri){
min1[node]=num[node]=1;
return ;
}
int t=(le+ri)>>1;
buildtree(le,t,node<<1);
buildtree(t+1,ri,node<<1|1);
pushup(node);
}
void update(int l,int r,ll x,int le,int ri,int node){
if(l<=le&&ri<=r){
lazy[node]+=x;
num[node]+=x*(ll)(ri-le+1);
min1[node]+=x;
return ;
}
pushdown(node,ri-le+1);
int t=(le+ri)>>1;
if(l<=t) update(l,r,x,le,t,node<<1);
if(r>t) update(l,r,x,t+1,ri,node<<1|1);
pushup(node);
}
ll query_sum(int l,int r,int le,int ri,int node){
if(l<=le&&ri<=r) return num[node];
pushdown(node,ri-le+1);
ll ans=0;
int t=(le+ri)>>1;
if(l<=t) ans+=query_sum(l,r,le,t,node<<1);
if(r>t) ans+=query_sum(l,r,t+1,ri,node<<1|1);
return ans;
}
ll query_min(int l,int r,int le,int ri,int node){
if(l<=le&&ri<=r) return min1[node];
pushdown(node,ri-le+1);
ll ans=999999999999ll;
int t=(le+ri)>>1;
if(l<=t) ans=min(ans,query_min(l,r,le,t,node<<1));
if(r>t) ans=min(ans,query_min(l,r,t+1,ri,node<<1|1));
return ans;
}
int main(){
int T,cas=1,n,m,a,b,c;
char ch[10];
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=0;i