hdu6162 Ch’s gift】的更多相关文章

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6162 题目: Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 526    Accepted Submission(s): 177 Problem Description Mr. Cui is working of…
 题意:一棵树,每个点有个权值,m次询问,每次给你一条链和两个值a,b,问你这条链上权值在[a,b]之间的权值的和是多少. std竟然是2个log的……完全没必要链剖,每个结点的主席树从其父节点转移过来,这样每个结点的主席树存储的就是它到根点的权值. 然后链询问,直接在主席树上作差,T[u]+T[v]-T[lca(u,v)]-T[fa(lca(u,v))]即可.只有一个log. 当然要先离散化. #include<cstdio> #include<algorithm> #inclu…
Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1354    Accepted Submission(s): 496 Problem Description Mr. Cui is working off-campus and he misses his girl friend very much. After a w…
Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 662    Accepted Submission(s): 229 Problem Description Mr. Cui is working off-campus and he misses his girl friend very much. After a wh…
Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2534    Accepted Submission(s): 887 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6162 Problem Description Mr. Cui is working off-campu…
Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing and turning, he decides to get to his…
/* HDU 6162 - Ch’s gift [ LCA,线段树 ] | 2017 ZJUT Multi-University Training 9 题意: N节点的树,Q组询问 每次询问s,t两节点之间的路径上点权值在[a,b]之间的点权总和 分析: 求出每个询问的LCA,然后离线 按dfs顺序更新树状数组,即某点处树状数组中存的值为其所有祖先节点的值 每个点处对答案的贡献为: 当其为第 i 个 lca 时, ans[i] -= 2 * query(a,b) , 再特判该节点 当其为第 i…
Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing and turning, he decides to get to his girl friend's city and of course, with well-chosen gifts. He knows neither too low the price could a gift be sinc…
题意: 已知树上的每个节点的值和节点之间的关系建成了一棵树,现在查询节点u到节点v的最短路径上的节点值在l到r之间的节点值的和. 思路: 用树链剖分将树映射到线段树上,线段树上维护3个值,max,min和sum即可. 接下来就是一个简单的线段树上的查询. #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<vector> #inclu…
题意:给定上一棵树,每个树的结点有一个权值,有 m 个询问,每次询问 s, t ,  a, b,问你从 s 到 t 这条路上,权值在 a 和 b 之间的和.(闭区间). 析:很明显的树链剖分,但是要用线段树来维护,首先先离线,然后按询问的 a 排序,每次把小于 a 的权值先更新上,然后再查询,这样就是区间求和了,算完小于a的,再算b的,最答案相减就好了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #inc…