
数据结构
文章平均质量分 81
小小小小葱
这个作者很懒,什么都没留下…
展开
-
uva12003 - Array Transformer 分块结构
Write a program to transform an array A[1], A[2], . . . , A[n] according to m instructions. Each instruction(L, R, v, p) means: First, calculate how many numbers from A[L] to A[R] (inclusive) are stri原创 2015-07-09 16:33:48 · 841 阅读 · 0 评论 -
poj2886 Who Gets the Most Candies? 线段树
Who Gets the Most Candies?Time Limit: 5000MS Memory Limit: 131072KTotal Submissions: 10876 Accepted: 3383Case Time Limit: 2000MSDescriptionN children are原创 2015-02-03 20:35:39 · 373 阅读 · 0 评论 -
uva1479 - Graph and Queries Treap名次树
You are given an undirected graph with N vertexes andM edges. Every vertex in this graph has an integer value assigned to it at the beginning. You're also given a sequence of operations and you need原创 2014-12-08 17:22:16 · 484 阅读 · 0 评论 -
uva11922 - Permutation Transformer 伸展树
Permutation Transformer Write a program to transform the permutation 1, 2, 3,..., n according to m instructions. Each instruction(a, b) means to take out the subsequence from thea-原创 2014-12-23 15:29:25 · 366 阅读 · 0 评论 -
uva11996 - Jewel Magic 伸展树
Problem JJewel MagicI am a magician. I have a string of emeralds and pearls. I may insert new jewels in the string, or remove old ones. I may even reverse a consecutive part of the string. At原创 2014-12-23 15:42:09 · 1679 阅读 · 0 评论 -
poj2828 Buy Tickets 单点更新线段树
Buy TicketsTime Limit: 4000MS Memory Limit: 65536KTotal Submissions: 14377 Accepted: 7183DescriptionRailway tickets were difficult to buy around the Lunar New Y原创 2015-01-27 12:06:08 · 398 阅读 · 0 评论 -
uva12206 - Stammering Aliens 哈希LCP和后缀数组两种做法
Dr. Ellie Arroway has established contact with an extraterrestrialcivilization. However, all efforts to decode their messages have failed so farbecause, as luck would have it, they have stumbled upon原创 2014-12-01 17:43:20 · 960 阅读 · 0 评论 -
后缀数组
西安回来后一个月没写代码了,前段时间太忙,这两天算是好点了,学习了一下后缀数组。 这里有几个关键的数组。 s是原始字符数组,sa是后缀数组,sa[i]表示第i大后缀的开始位置,rank是名次数组,rank[i]表示位置i的数组是第几大(相当于sa[i]反过来),height[i]是后缀sa[i]和后缀sa[i-1]的最长公共前缀,x是当前rank,y是辅助数组。 主要思路就是这个原创 2014-11-25 18:48:52 · 329 阅读 · 0 评论 -
uva11107 - Life Forms 后缀数组
Problem C: Life FormsYou may have wondered why most extraterrestrial life forms resemble humans,differing by superficial traits such as height, colour, wrinkles,ears, eyebrows and the like. A few be原创 2014-11-26 19:38:39 · 585 阅读 · 0 评论 -
hdu5044 Tree 上海网络赛1003 LCA+输入输出外挂
TreeTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 668 Accepted Submission(s): 141Problem DescriptionYou are given a tree (an a原创 2014-09-28 16:04:10 · 700 阅读 · 0 评论 -
uva11983 - Weird Advertisement 矩形面积并 重叠大于等于K次的面积
GWeird AdvertisementRenat Mullakhanov (rem), oneof the most talented programmers in the world, passed away on March 11, 2011.This is very sad news for all of us. His team went to A原创 2014-08-17 16:53:43 · 484 阅读 · 0 评论 -
uva1493 - Draw a Mess 并查集路径压缩
It's graduated season, every students should leave something on the wall, so....they draw a lot of geometry shape with different color.When teacher come to see what happened, without getting angry,原创 2014-12-26 19:54:22 · 428 阅读 · 0 评论 -
uva10829 - L-Gap Substrings 后缀数组+RMQ
Problem JL-Gap SubstringsInput:StandardInputOutput: Standard Output If a string is in the form UVU, where Uis not empty, andV has exactly L characters, we say UVUis anL-Gap string. For exa原创 2015-02-04 20:25:51 · 817 阅读 · 0 评论 -
poj3693 Maximum repetition substring 后缀数组+RMQ
Maximum repetition substringTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7496 Accepted: 2244DescriptionThe repetition number of a string is defin原创 2015-02-02 19:53:51 · 398 阅读 · 0 评论 -
uva11297 - Census 线段树套线段树
C. CensusTime Limit: 8 secDescriptionThis year, there have been many problems with population calculations, since in some cities, there are many emigrants, or the populat原创 2015-07-08 17:23:47 · 495 阅读 · 0 评论 -
poj1195 Mobile phones 二维线段树和二维树状数组两种做法 树套树
Mobile phonesTime Limit: 5000MS Memory Limit: 65536KTotal Submissions: 15849 Accepted: 7321DescriptionSuppose that the fourth generation mobile phone base station原创 2015-03-20 21:10:46 · 458 阅读 · 1 评论 -
Codeforces Round #136 (Div. 2) D. Little Elephant and Array 线段树 离线处理
D. Little Elephant and Arraytime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Little Elephant loves playing with a原创 2015-03-08 20:22:01 · 527 阅读 · 0 评论 -
poj2991 Crane 向量旋转+线段树
CraneTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 3962 Accepted: 1072 Special JudgeDescriptionACM has bought a new crane (crane -- jeřáb) . The c原创 2015-03-08 20:02:30 · 397 阅读 · 0 评论 -
伸展树
伸展树(Splay Tree),也叫分裂树,是一种二叉排序树,它能在O(log n)内完成插入、查找和删除操作。 旋转操作(左旋右旋)和前面的treap一样,伸展树最重要的操作是伸展操作,它把一个指定结点x自底向上旋转到根结点。分三种情况: 情况一:节点x的父节点y是根节点。这时,如果x是y的左孩子,我们进行一次Zig(右旋)操作;如果x是y的右孩子,则我们进行一次Zag(原创 2014-12-23 15:22:35 · 497 阅读 · 0 评论 -
Codeforces Round #285 (Div. 2) D. Misha and Permutations Summation 康托展开 树状数组+二分
D. Misha and Permutations Summationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define the sum of two permu原创 2015-01-23 19:36:38 · 670 阅读 · 0 评论 -
hdu4521 小明系列问题——小明序列 线段树 间隔大于d的最长上升子序列
小明系列问题——小明序列Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 2000 Accepted Submission(s): 610Problem Description 大家都知道小明最喜欢研究跟序原创 2015-02-22 11:43:21 · 410 阅读 · 0 评论 -
uva1406 - A Sequence of Numbers 树状数组
You are given a sequence of N integers (each within the range[0, 216 - 1]) along with P operations and in order to solve this problem you need to process the operations instructed as follows.T原创 2015-01-03 15:34:41 · 523 阅读 · 2 评论 -
hdu4288 Coder 线段树
CoderTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3567 Accepted Submission(s): 1390Problem Description In mathematics and c原创 2015-02-05 18:40:26 · 383 阅读 · 0 评论 -
uva10526 - Intellectual Property 后缀数组
Problem A: Intellectual PropertyTDP Inc. has decided to sue JCN Inc. for copyright infringement. To this end, TDP wishes to find infringing segments within JCN's code base, to show to selected media原创 2015-02-05 18:31:52 · 518 阅读 · 0 评论 -
poj2464 Brownie Points II 树状数组
DescriptionStan and Ollie play the game of Odd Brownie Points. Some brownie points are located in the plane, at integer coordinates. Stan plays first and places a vertical line in the plane. The lin原创 2014-08-16 19:36:08 · 487 阅读 · 0 评论 -
uva1455 - Kingdom 线段树+并查集
There were n cities in an ancient kingdom. In the beginning of the kingdom, all cities were isolated. Kings ordered their subjects to construct roads connecting cities. A lot of roads were built with原创 2014-08-13 19:08:25 · 616 阅读 · 0 评论 -
uva11992 - Fast Matrix Operations 区间修改 二维线段树
//修改、查询区间均为[y1,y2]struct IntervalTree{ //同一结点先考虑set,再考虑add //sumv[o],minv[o],maxv[o]保存的是以o为根结点的树内修改后的和,最大,最小值,o的父节点及以上结点修改的情况没有包括在里面 int setv[MAXNODE],addv[MAXNODE],sumv[MAXNODE],minv[MAX原创 2014-03-12 11:51:16 · 756 阅读 · 0 评论 -
uva1400 区间最大连续和 线段树
After doing Ray a great favor to collect sticks for Ray, Poor Neal becomes very hungry. In return for Neal's help, Ray makes a great dinner for Neal. When it is time for dinner, Ray arranges all the d原创 2014-03-10 20:02:01 · 514 阅读 · 0 评论 -
uva11987 - Almost Union-Find 并查集删除元素
Problem AAlmost Union-FindI hope you know the beautiful Union-Find structure. In this problem, you're to implement something similar, but not identical.The data structure you need to write i原创 2014-03-02 22:06:40 · 537 阅读 · 0 评论 -
uva10410 - Tree Reconstruction BFS和DFS重建树
You have just finished a compiler design homework question whereyou had to find the parse tree of an expression. Unfortunately youleft your assignment in the library, but luckily your friend picked it原创 2014-03-01 11:31:16 · 1150 阅读 · 0 评论 -
堆 优先队列
首先看完全二叉树的定义:若设二叉树的深度为h,除第 h 层外,其它各层 (1~h-1) 的结点数都达到最大个数,第 h 层所有的结点都连续集中在最左边,这就是完全二叉树。 如果一个完全二叉树的某个结点值都不大于或小于他的父结点,那就叫做堆。根结点是所有结点里最大的叫大根堆,最小的叫小根堆。 比如: 9-1 a是大根堆,9-2 a是小根堆,剩下的都不是堆(因为不是完全二叉树)原创 2013-06-03 12:53:01 · 2158 阅读 · 0 评论 -
uva12232 - Exclusive-OR 加权并查集
You are not given n non-negative integersX0, X1,..., Xn-1 less than220, but they do exist, and their values never change.I'll gradually provide you some facts about them, and ask you some ques原创 2014-02-27 18:48:21 · 826 阅读 · 0 评论 -
并查集
在一些有N个元素的集合应用问题中,我们通常是在开始时让每个元素构成一个单元素的集合,然后按一定顺序将属于同一组的元素所在的集合合并,其间要反复查找一个元素在哪个集合中。 有n个元素,一开始每个元素都是一个集合,我们用p[x]表示x的父亲结点,当p[x]=x时是根结点,那么一开始p[i]=i(i=1...n)。如果想把两个集合合并,只需要把一个集合的根结点接到另一个集合的根结点下就行了(我们只原创 2013-08-07 22:23:38 · 847 阅读 · 0 评论 -
uva10158 - War 并查集判断同伙的两种方法
Problem B: War A war is being lead between two countries, A and B. As a loyal citizen of C, you decide to help your country’s espionage by attending the peace-talks taking place these days原创 2014-01-24 12:29:53 · 633 阅读 · 0 评论 -
哈夫曼树
给定n个权值作为n个叶子结点,构造一棵二叉树,若带权路径长度达到最小,称这样的二叉树为最优二叉树,也称为哈夫曼树(Huffman tree)。结点的带权路径长度为:从根结点到该结点之间的路径长度与该结点的权的乘积。树的带权路径长度规定为所有叶子结点的带权路径长度之和。 1*3+2*3+3*2+4*1 = (1+2)+(1+2+3)+(1+2+3+4) =19 整个树的带权原创 2013-08-09 11:25:41 · 786 阅读 · 0 评论 -
离散化+树状数组 求逆序对数
除了归并排序,也可以用树状数组求逆序对数。先看 POJ 2299Ultra-QuickSortTime Limit: 7000MS Memory Limit: 65536KTotal Submissions: 32606 Accepted: 11633DescriptionIn this problem, you have原创 2013-05-28 11:35:57 · 710 阅读 · 0 评论 -
RMQ sparse-table
RMQ (Range Minimum/Maximum Query) 区间最小值问题。 sparse-table算法复杂度O(nlogn) 设d[i][j]表示从i开始,长度问哦2^j的一段元素中的最小值,等于前一半的最小值和后一半的最小值中小的那个,也就是d[i][j]=min(d[i][j-1],d[i+2^(j-1),j-1])。询问的时候找到2^k d一维大小为N,二维大小原创 2014-03-07 10:57:49 · 527 阅读 · 0 评论 -
upc1976 树状数组和线段树两种做法
1976: problem FTime Limit: 3 Sec Memory Limit: 64 MBSubmit: 78 Solved: 17[Submit][Status][Web Board]Description在一个小镇上住着n位武林高手,他们互相之间经常PK,不过PK的时候必须要有一位裁判在场。这个小镇上的房子从1—n依次排列(一条直线上),两个人要单原创 2013-12-03 22:58:30 · 540 阅读 · 0 评论 -
uva11525 - Permutation 线段树加速康托展开
Problem FPermutationInput: Standard InputOutput: StandardOutput Given N and K find the N’thpermutation of the integers from 1 to K when those permutations arelexicographically ordered. N s原创 2014-03-16 11:20:38 · 699 阅读 · 0 评论 -
hdu 3397 Sequence operation 线段树 区间和 连续1的个数
Sequence operationTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6032 Accepted Submission(s): 1784Problem Descriptionlxhgww got原创 2014-08-13 15:26:18 · 524 阅读 · 0 评论