Victor and Toys Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)Total Submission(s): 654    Accepted Submission(s): 219 Problem Description Victor has n toys, numbered from 1 to n. The beauty of the i-th toy is wi…
http://acm.hdu.edu.cn/showproblem.php?pid=5419 题意 n个物品,标号1-n,物品i有权值wi.现在有m个区间[l,r],从中任意选三个区间i,j,k,求物品编号在区间[ max{li,lj,lk},min{ri,rj,rk} ]的权值和,问总期望是多少. 分析 选择区间的总情况数为C(m,3)=m*(m-1)*(m-2)/6.对于物品,其存在贡献的地方一定是包含它的区间,那么先求出包含每个物品的区间数,用区间覆盖的思想,假设有num个区间包含权值为w…
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…
HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号节点开始到x节点,所能经过的路径的权值最大为多少:操作二为修改,给出一个节点x和值val,将x的权值改为val. 可以看出是树上修改问题.考虑的解题方式有DFS序+线段树,树链剖分,CXTree.由于后两种目前还不会,选择用DFS序来解决. 首先对树求DFS序,在求解过程当中,顺便求解树上前缀和(p…
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #include <bits/stdc++.h> #define nmax 200000 using namespace std; struct Tree{ int l,r,val; int lazy; int mid(){ return (l+r)>>1; } }; Tree tree[nmax&…
HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 using namespace std; struct Tree{ int l,r,val; int lazy; int mid(){ return (l+r)>>1; } }; Tree tree[nmax<<2]; int num[nmax<<2]; void Pus…
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对最少的个数. 前置技能 环序列 还 线段树的逆序对求法 逆序对:ai > aj 且 i < j ,换句话说数字大的反而排到前面(相对后面的小数字而言) 环序列:把第一个放到最后一个数后面,就是一次成环,一个含有n个元素序列有n个环序列. 线段树的逆序对求法:每个叶子节点保存的是当前值数字的个数.根…
HDU.1689 Just a Hook (线段树 区间替换 区间总和) 题意分析 一开始叶子节点均为1,操作为将[L,R]区间全部替换成C,求总区间[1,N]和 线段树维护区间和 . 建树的时候初始化为1,更新区间时候放懒惰标记,下推标记更新区间和. 由于是替换,不是累加,所以更新的时候不是+=,而是直接=. 注意这点就可以了,然后就是多组数据注意memset,因为这个WA几发. 代码总览 #include <bits/stdc++.h> #define maxn 200010 #defin…
// hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #i…
// hdu 1166 敌兵布阵 线段树 点更新 // // 这道题裸的线段树的点更新,直接写就能够了 // // 一直以来想要进线段树的坑,结果一直没有跳进去,今天算是跳进去吧, // 尽管十分简单.十分的水,继续加油 #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits…