摘要: 二维坐标离散化 离散化的思想就是将分布大却数量少(即稀疏)的数据进行集中化的处理,这样可以有利于程序的空间与时间,能减少遍历次数与空间储存。 思想理解起来其实道理很简单,如坐标(3,2000),(10005,31),(10006,5)离散至新图,先看x坐标,3个点有3,10005,10006,离散后 阅读全文
posted @ 2019-05-13 09:28 starve_to_death 阅读(443) 评论(0) 推荐(0) 编辑
摘要: 1 #include<bits/stdc++.h> 2 using namespace std; 3 inline int read(){ 4 int sum=0,x=1; 5 char ch=getchar(); 6 while(ch<'0'||ch>'9'){ 7 if(ch=='-') 8 x 阅读全文
posted @ 2019-05-10 17:20 starve_to_death 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 1 const int N = 1e5 + 5; 2 vector<int> g[N]; 3 int fa[N], dp[N], sz[N], son[N], top[N], dfn[N], to[N], cnt = 0, n; 4 void dfs1(int u, int o) { 5 fa[u] 阅读全文
posted @ 2019-05-09 18:18 starve_to_death 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int M=3e5+5; 4 struct node{ 5 int l,r,cnt,lazy; 6 node(int l1=0,int r1=0,int cnt1=0,int lazy1 阅读全文
posted @ 2019-05-09 18:15 starve_to_death 阅读(95) 评论(0) 推荐(0) 编辑
摘要: 在写的时候加了判断询问位置先后的swap结果wa了快十次了,不知道为什么; http://acm.hdu.edu.cn/showproblem.php?pid=1754 阅读全文
posted @ 2019-05-06 21:04 starve_to_death 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 不开longlong见祖宗 题目没说操作中的a,b大小要注意 接着就是状压+线段树 http://poj.org/problem?id=2777 阅读全文
posted @ 2019-05-06 18:24 starve_to_death 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 区间修改&&单点查询(树状数组) #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<vector> #include<list> #include<ma 阅读全文
posted @ 2019-05-06 16:27 starve_to_death 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 树的直径: 利用了树的直径的一个性质:距某个点最远的叶子节点一定是树的某一条直径的端点。 先从任意一顶点a出发,bfs找到离它最远的一个叶子顶点b,然后再从b出发bfs找到离b最远的顶点c,那么b和c之间的距离就是树的直径。 用dfs也可以。 http://poj.org/problem?id=19 阅读全文
posted @ 2019-05-05 23:49 starve_to_death 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 图不一定联通,所以用并查集找各个联通块的祖先分别建图,之后就和LCA的步骤差不多了 阅读全文
posted @ 2019-05-04 17:34 starve_to_death 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 在dfs的过程中维护三个数组: deep[i],表示i点在树中的深度; grand[x][i],表示x的第2^i个祖先的节点编号; dis[x][i],表示x到它2^i祖 先的距离。 阅读全文
posted @ 2019-05-04 14:45 starve_to_death 阅读(156) 评论(0) 推荐(0) 编辑