![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
shinimashzi
这个作者很懒,什么都没留下…
展开
-
线段树入门
今天看了一天的线段树,寒假写过,但是寒假连区间更新里的lazytag都没有理解,也不知道当时写的什么鬼了。 重要操作: 单点更新 单点查询区间更新区间查询主要关于lazytag,其实就是一个标记,我理解的是,标记此区间已经计算正确,但是子区间的值还未更新, 所以最好在区间查询和更新时都下推一下tag。下推tag时的操作和具体题目有关。题目:HDU - 1754 题解 (单点更新,原创 2017-06-06 00:01:26 · 220 阅读 · 0 评论 -
POJ - 1177 Picture (线段树 + 扫描线)
POJ - 1177 题目题意: 给一堆矩形,求这些矩形的周长#include #include #include #include #include using namespace std;#define met(a,b) memset(a,b,sizeof(a))const int maxn = 5010;struct node{ int x,v,y1原创 2017-06-15 00:20:14 · 258 阅读 · 0 评论 -
HDU - 1255 覆盖的面积(线段树 + 扫描线)
HDU - 1255 题目题意: 额中文题基本就是求矩形面积,改一点就好了。#include #include #include #include #include using namespace std;#define met(a,b) memset(a,b,sizeof(a))const double eps = 10e-6;const int maxn = 10原创 2017-06-15 00:22:41 · 214 阅读 · 0 评论 -
POJ - 3349 Snowflake Snow Snowflakes (hash)
POJ - 3349 Snowflake Snow Snowflakes 题目题意:求一堆雪花,有没有两片相同,给你的序列可能是顺时针,也可能是逆时针。思路 : 真的才发现我stl学的简直烂到爆炸,现在都不知道之前c++的CE从何而来。这题直接上map会超时,所以我们要考虑一种更快的查找,那么就是hash啦~不过说起来,我的hash的散列函数也不是特别高效。代码:原创 2017-06-15 00:31:48 · 210 阅读 · 0 评论 -
关于二叉树
HDU - 1710题意:前序中序求后序#include #include #include using namespace std;const int maxn = 1050;int a[maxn],b[maxn];int n;struct node{ int v,l,r;}tr[maxn << 2];int num = 0;int build(int原创 2017-07-01 15:59:07 · 143 阅读 · 0 评论 -
HDU - 3974 Assign the task (线段树 + dfs序)
HDU - 3974题意:有个公司有一些关系,每个人(除了boss)都有且仅有一个上司,这就是一棵树的关系,然后会有一些操作,C i,询问第i个人现在的任务,T x y,把y任务给x, 给x相当于给x及他所有的下属,新任务会覆盖旧任务思路:这是我写的第一个(除了联通图那些)需要用dfs序的题,最近有毒,wa到不敢相信自己....因为i节点的子树在dfs访问序列中肯定是连续的,所以可以把原创 2017-07-18 19:02:34 · 279 阅读 · 0 评论 -
HDU - 5861 Road(线段树)
HDU - 5861Problem DescriptionThere 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,原创 2017-07-19 11:38:13 · 260 阅读 · 0 评论 -
K-th number
归并树划分树分块目前只看会了第一种,在POJ - 2104上跑了接近4s,POJ - 2761直接超时。发现自己的二分....真的水归并树:#include #include #include #include #include using namespace std;const int maxn = 1e5 + 10;const int inf = 0x3f3f3原创 2017-07-20 19:58:52 · 232 阅读 · 0 评论 -
HDU - 5862 Counting Intersections (扫描线应用)
HDU - 5862Problem DescriptionGiven some segments which are paralleled to the coordinate axis. You need to count the number of their intersection.The input data guarantee that no two segmen原创 2017-07-20 23:31:47 · 346 阅读 · 0 评论 -
求逆序对
POJ - 2299题意就是求逆序对,当然还有别的方法,如果之后写了会补充树状数组:#include #include #include #include using namespace std;#define ll long longconst int maxn = 5e5 + 50;int d[maxn],id[maxn];ll sum[maxn];int lo原创 2017-07-21 23:49:51 · 241 阅读 · 0 评论 -
HDU - 1540Tunnel Warfare(线段树 单点更新 区间查询)
HDU - 1540 题目链接这一题看上去是单点查询,其实是查询区间啦,查询x左边的靠右的区间和右边的靠左的区间的和。今天看了一篇博客,感觉说的真的很好,自己动不动就去翻discuss和题解真的挺不好的。刷题是为了什么呢,又不是为了题量,而是为了自己的思维能力。思维能力上不去,写的题再多有什么用啊。在这里立下flag,以后除非卡成10天半个月或更久过不了题,再去翻题解,翻题解也别原创 2017-06-10 23:45:02 · 211 阅读 · 0 评论 -
HDU - 1754 I Hate It(简单线段树 单点更新+区间查询)
HDU - 1754 http://acm.hdu.edu.cn/showproblem.php?pid=1754 思路:单点更新+区间查询#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int inf = 0x3f3f3f3原创 2017-06-06 22:05:24 · 223 阅读 · 0 评论 -
HDU - 1698 Just a Hook(区间更新)
HDU - 1698 http://acm.hdu.edu.cn/showproblem.php?pid=1698 思路:区间更新 直接整段区间求和#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int maxn = 100000 + 1原创 2017-06-06 22:07:53 · 155 阅读 · 0 评论 -
POJ - 3468 A Simple Problem with Integers(线段树 区间更新 区间查询)
POJ - 3468 http://poj.org/problem?id=3468 思路:区间更新+区间查询 注意tag也是ll的。 代码:#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define ll long longconst in原创 2017-06-06 22:09:46 · 151 阅读 · 0 评论 -
ZOJ - 1610 Count the Colors(区间更新)
题意:给(a,b)线段染色为c,这种操作有n次!所有的点不超过8000。输出index的颜色能看见几次。 思路:区间更新。 所以我在结构体里直接上了map来存颜色,感觉有点蠢。。。但是好歹写出来了不是。。(只能这么安慰自己了) 因为有区间更新,所以也涉及到下推tag。这里要维护的要想到的一点就是,左儿子的尾和右儿子的头如果同色,这个算出现一次。其余的都很好想了,尤其是我这种弃疗写法。。#incl原创 2017-06-06 22:21:08 · 139 阅读 · 0 评论 -
HDU - 3308 LCIS (线段树 单点更新 区间查询)
hdu 3308 http://acm.hdu.edu.cn/showproblem.php?pid=3308题意:要维护最长连续子序列思路:区间查询,需要知道每段的前缀最大lcis,后缀lcis,每次用子节点来更新父节点的值的时候就要比较左右结点的后缀和前缀能否相连,左节点的lcis,右结点的lcis,这中间最长的就是父节点的lcis。这两天深刻让我认识到了我的线段数和别人的线段树的差别。我的线段原创 2017-06-06 22:29:16 · 311 阅读 · 0 评论 -
POJ - 3264 Balanced Lineup(线段树 区间查询 无更新/ RMQ算法)
题目: http://poj.org/problem?id=3264 DescriptionFor the daily milking, Farmer John’s N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate原创 2017-06-09 00:12:30 · 229 阅读 · 0 评论 -
POJ - 2528 Mayor's posters (线段树离散化+区间更新)
POJ - 2528 http://poj.org/problem?id=2528 以为过了但是看了discuss,有组数据有问题,先放着,之后会回来改。 想要学习骚气的写法所以改了改自己的线段树,第一次自己能主动想到离散化,结果还是有问题。//离散化+线段树(区间更新)/*过不了的数据335 64 56 83 主要是这组1 101 36 1051 42 68原创 2017-06-09 00:37:39 · 233 阅读 · 0 评论 -
HDU - 4027 Can you answer these queries? (线段树 区间更新 区间查询)
HDU - 4027 http://acm.hdu.edu.cn/showproblem.php?pid=4027题意:更新的时候把要求区间内的值都更新为自己开根号,查询时查询区间和。思路: 感觉自己有个不好的习惯,有题目没思路时老是容易去看题解或是discuss,这个习惯真的要改一下。这个题由于是根号,所以必须得更新到点,然后会发现,每次开根号一个数会很快变成1,这时再对这段区间原创 2017-06-09 23:37:46 · 168 阅读 · 0 评论 -
HDU - 1166 敌兵布阵(线段树/树状数组)
HDU - 1166 题目思路: 最基础的线段树,之前写过了(单点更新 + 区间求和)试了试树状数组,毕竟今天的补题也用到了。#include #include #include using namespace std;#define met(a,b) memset(a,b,sizeof(a))const int maxn = 5e4 + 10;int c[maxn];原创 2017-06-09 23:46:18 · 195 阅读 · 0 评论 -
POJ - 3764 The xor-longest Path (01字典树)
POJ - 3764 题意: 求树上两个结点间路径的XOR值的最大值。 思路: 可以知道任意两个结点,设从根到这个结点的dis[u] = XOR路径和,那么u->v = dis[u]XORdis[v]; 因为他们的dis[lca(u,v)]会因为被XOR两次而不会对结果造成影响,所以这就成了求dis[i]中两个值的XOR最大值,可以用01字典树维护,每对一个dis[i]值,先查询再插入。#i原创 2017-08-04 17:15:42 · 273 阅读 · 0 评论