hdu 5861 Road 两棵线段树】的更多相关文章

传送门:hdu 5861 Road 题意: 水平线上n个村子间有 n-1 条路. 每条路开放一天的价格为 Wi 有 m 天的操作,每天需要用到村子 Ai~Bi 间的道路 每条路只能开放或关闭一次. (不能重复开关) 求每天的最小花费. 思路: 第一次线段树:维护每条路第一次和最后一次被用到的天数.以下代码维护了 mn:第一次被用到,mx:最后一次被用到,lazy:被更新的最大值若当前区间被lazy维护而没有更新到点,那么这个子节点的最小值就可能被改变.所以我这里的子节点更新是根据父节点的最大和最…
搞了一晚上,错了,以后回头再来看 /* 对于每次更新,先处理其儿子方向,再处理其父亲方向 处理父亲方向时无法达到根,那么直接更新 如果能达到根,那么到兄弟链中去更新,使用bfs序 最后,查询结点v的结果就是dfs序线段树上的查询值+bfs线段树上的查询值 */ #include<iostream> #include<cstring> #include<vector> #include<queue> using namespace std; #define m…
Road 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Description There are n villages along a high way, and divided the high way into n-1 segments. Each segment would charge a certain amount of money for being open for one day, and you can…
HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号节点开始到x节点,所能经过的路径的权值最大为多少:操作二为修改,给出一个节点x和值val,将x的权值改为val. 可以看出是树上修改问题.考虑的解题方式有DFS序+线段树,树链剖分,CXTree.由于后两种目前还不会,选择用DFS序来解决. 首先对树求DFS序,在求解过程当中,顺便求解树上前缀和(p…
You are given a tree with N nodes. The tree nodes are numbered from 1 to N and have colors C1, C2,. . . , CN initially. You have to handle M instructions on the tree of the following forms:• 0 u c: Change the color of node u to c.• 1 u v: Output the…
Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16941    Accepted Submission(s): 5190 Problem Description Give you a sequence and ask you the kth big number of a inteval.   Input The…
http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给出一个矩阵,然后q个询问,每个询问有a,b,c,代表(a,b)这个点上下左右c/2的矩形区域内的(最大值+最小值)/2是多少,并且将(a,b)的值替换成这个答案. 思路:很久以前被暴力跑过去的一道题,今天怎么交也过不去...果然是人品爆发了. 学了一下树套树,一开始觉得挺容易理解,但是后面PushUp那里挺难懂的(对我来说). 我的理解: 对于每个线段树的结点开一棵线段树,即tree[x][y]…
题目描述: Description This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order if k = 1 or in non-increasing ord…
R - Weak Pair HDU - 5877 离散化+权值线段树 这个题目的初步想法,首先用dfs序建一颗树,然后判断对于每一个节点进行遍历,判断他的子节点和他相乘是不是小于等于k, 这么暴力的算法很自然的超时了. 然后上网搜了一下题解,感觉想的很巧妙. 就是我们要搜 子节点和父节点的乘积小于一个定值的对数. 一般求对数,有逆序对,都是把满足的放进去,到时候直接求答案就可以了.这个题目也很类似,但是还是有很大的区别的. 这个题目就是先把所有a[i] 和 k/a[i] 都放进一个数组,离散化,…
HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1391    Accepted Submission(s): 483 Problem Description The Game “Man Down 100 floors” is an famous and interesting ga…