最近刚学线段树,做了些经典题目来练手 Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 24370 Accepted Submission(s): 12156 Problem Description In the game of DotA, Pudge's meat hook is actually the most h…
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecut…
学习线段树第二天,这道题属于第二简单的线段树,第一简单是单点更新,这个属于区间更新. 区间更新就是lazy思想,我来按照自己浅薄的理解谈谈lazy思想: 就是在数据结构中,树形结构可以线性存储(线性表)也可以树状存储(链表) 树形typedef struct node { int data; struct node* Lchild; struct node* Rchild; }Btree,*BTree;BTree = (BTree)malloc(Btree);好像是这样吧...大半个暑假过去忘得…
题解: 和hdu1166敌兵布阵不同的是 这道题需要区间更新(成段更新). 单点更新不用说了比较简单,区间更新的话,如果每次都更新到底的话,有点费时间. 这里就体现了线段树的另一个重要思想:延迟标记. 在定义树节点结构体的时候加一个标记:flag. typedef struct node { node():l(0),r(0),data(0),flag(0){} //构造函数 初始化数据成员 int l,r; int data; //每个节点的数据 int flag; //延迟标记 }TNode;…
题目链接:https://vjudge.net/problem/HDU-1698 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length. Now Pudge wants to do…
Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 17124    Accepted Submission(s): 8547 Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing f…
共有Q个更新,每次更新给更新的区间一个标记,表示该区间是在哪一次被更新,最后统计答案是以最近被更新的值为答案. AC代码: #include<cstdio> const int maxn=8e5+5; struct node{ int num,val; }tree[maxn]; int num,val; void Build(int l,int r,int ll,int rr,int cur){ if(l==ll&&r==rr){ tree[cur].num=num; tree…
http://acm.hdu.edu.cn/showproblem.php?pid=1698 Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same len…
Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 22730    Accepted Submission(s): 11366 Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible thing…
hdu_1698Just a Hook(线段树) 标签: 线段树 题目链接 题意: 一个英雄的技能是发射一个长度为n的金属链,初始的金属链都是铁做的,标记为1,我们可以对于某个区间修改它的金属材质,如果修改为银的标号为2,金的标号为3,现在问你经过一系列的修改后整条链子上的标记和为多少 题解: 很容易想到这个题和区间染色的问题很像 代码: #include<cstdio> #include<cstring> #include<algorithm> using names…