Disjoint-set:
capacity 2492
Just can not add the same point again in the same set, a simple application is the disjoint-set using disjoint-set to determine whether there had been this element.
Solution to a problem link: Click here
HUD 3461 codelock
N has a long string lock, this lock find how many different way to unlock the lock has a number of sections can be rotated by rotating the case of two mutually belong to the same arrival unlocking. So the title is the number of the required range.
Solution to a problem link: Click here
Estimated 3261 Connections in Galaxy War
There are N number of planets, numbered from 0 to n-1 each have a respective planet energy value. Maximum energy output for each query values are linked. With disjoint-set links to determine the relationship, plus off-line processing reverse side and then record the answers and then output.
Solution to a problem link: Click here
POJ 1456 Supermarket
You give N pieces of different products, each item can be bought at most once asked you can get the most value. I used to be greedy to do, but the problem in a disjoint-set optimization will become very low complexity.
Solution to a problem link: Click here
Fenwick tree
HDU 3874 Necklace
Hands you a sequence of length N, then M is a query request interval calculated continuously and each segment Note: repeating elements appearing only once with a continuous map and to determine whether repeated, the sections are kept up off-line processing and then output the answer.
Solution to a problem link: Click here
HDU 2227 Find the nondecreasing subsequences
To give you an ordered sequence, find the number of sub-sequence does not drop, seemingly simple but is a combination of several algorithms is more classic is worth a good look.
Solution to a problem link: Click here
HDU 1394 Minimum Inversion Number
There is a permutation of n integers, the number of reverse obtains various arrangements, the number of reverse seek acceleration Fenwick tree
Solution to a problem link: Click here
·
Segment tree
POJ - 2528 Mayor's posters
N is given intervals and then find the section number of section typically cover the visible range of the coverage problem, but the amount of data required discretization of solving the problem, with this discretization is very clever, discrete segment tree last operation before use The number of inquiries interval.
Solution to a problem link: Click here
HDU - 1540 Tunnel Warfare
n Dorian villages land in a straight line, each can destroy a village can also rebuild a village, seeking the most consecutive number of villages that are disjoint-set to do, read the solution to a problem is found to maintain maximum continuous value segment tree.
Solution to a problem link: Click here
POJ 1436 Horizontally VisibleSegments
N given vertical segment, and asked the N line segments can be composed of the number of triangles. First, if we can range between any two vertical segments i and j obtained is visible, then we can use violence O (n ^ 3) traversing all the way to get the number of the triangle. So let's just find this matrix can be. This problem becomes a tree line sections covering coloring problem
Solution to a problem link: Click here
HDU 1542 Atlantis
N-dimensional plane parallel to the axis of the rectangle, these rectangles are now required total area. Very classic scan line segment tree, but simple
Solution to a problem link: Click here
UVA11297 Census
Give you a n * n matrix, the matrix also have a single point of most value to modify the query, two-dimensional tree line.
Solution to a problem link: Click here
HDU 6315 Weekly Operations
There are two arrays for one operation, and then seeking to drink interval, segment tree maintains a% b - b of the maximum value, and then pass under each update flag.
Solution to a problem link: Click here
HDU 1540 Tunnel Warfare
Give you the N building, building in a row three operations, query operation is to query the maximum continuous length.
But for the segment tree theme really can not think of a tree line, also had a simulation, then looked at problem solution is found to the issue of merger tree line interval of the estimated amount of data and then a big point, the simulation to make life difficult.
Solution to a problem link: Click here
RMQ
POJ 3264 Balanced Lineup
N you cows height arranged in a certain order, to find the difference between the highest and the shortest cows cows given interval. Liu Rujia example on the purple book, although not difficult but very classic, you need to preprocess the data, then the query.
Solution to a problem link: Click here
Poj 2452 Sticks Problem
Given a length n of the sequence, the sequence in the elements are not the same, asked to identify one pair (i, j), i <j, arr [k]> = i & arr [k] <= j, All (i < k <j). ji and then find the maximum difference value.
RMQ + half
Solution to a problem link: Click here
HDU2888 Check Corners
Given a matrix of n * m, to give a given query q, each query (r1, c1) of the upper left corner, (r2, c2) is the maximum sub-rectangles of the lower right corner, and determines whether there is the maximum in the top corner on the four sub-matrices?
Two-dimensional base of operations RMQ.
Solution to a problem link: Click here
POJ1785 Binary Search Heap Construction
Establishing a tree, each node has two keys, a key satisfying requirements of properties of the binary search tree, to meet the nature of the second node heap, Treap + RMQ
Solution to a problem link: Click here
HDU 3183 A Magic Lamp
For an n-digit, after removing m bits, the smallest number to get what is really not contact RMQ problem up, change my thinking delete the number change number so that we can use to pick RMQ solved.
Solution to a problem link: Click here
The diameter of the tree
POJ 2631 Roads in the North
There is a tree structure, you give all sides of the tree, expressed between u and v 2.1 distance edge cost Then you ask how much the distance between two points is the farthest tree? Tree with a diameter of classic examples It is contiguous table to represent a tree structure.
Solution to a problem link: Click here
HDU 3534 Tree
Given a tree of n nodes, each edge corresponds to a length, calculated from the maximum length between two nodes, and to identify a number of shared vertices.
Is the desire of the tree and dot diameter, the DFS do, also do tree DP. And that the above questions are the same as the classic title
Solution to a problem link: Click here
KMP:
uva1328 Period
For each of a length from the beginning of the prefix i (i> 1) whether the recurring substring A composition is seeking minimum cycle section KMP
We found that when the i-next [i] can be divisible by i times, then the s [1 ~ i-next [i]] is s [i-1] minimum cycle element, as for the number that is i / (i-next [I]) ..
Solution to a problem link: Click here
POJ2406 Power Strings
Minimum number of cycles to find a string section ..
First find the next array, then [len] -next length is the length of the minimum cycle section. Then special judge.
Solution to a problem link: Click here
HDU3336
Give you a string, the string request with all prefixes to match the sum of the number of times the string itself. Bare extension KMP, but in the end the process of seeking answers must fully understand the meaning of the KMP in next array.
Solution to a problem link: Click here
HDU 1867 A + B for you again
Give you two strings, the output string KMP used twice after they were combined, and then determine how to minimize composition may be such that the lexicographically
Solution to a problem link: Click here
POJ3080 Blue Jeans
N give you a string, the longest common subsequence of consecutive n want you to find this string is which. KMP then enumerate all substring matching to find that a lexicographically smallest
Solution to a problem link: Click here
POJ 2185 Milking Grid
Solving Minimum cycle section, row and column array nxet were run again, finally get the answer is the product of two results
Solution to a problem link: Click here
Suffix array
POJ1226 Substrings
N strings you, you ask for such a length of the longest substring in each substring requires the original string or strings against strings appear in both the original once. The output of the burst length can.
Enumerate all substring then use the suffix array
Solution to a problem link: Click here
URAL 1517. Freedom of choice
Give you two equal length strings, seeking their longest common continuous string. We suffix number as long as each can be used as a solution in the process of recording and the length can
Solution to a problem link: Click here
POJ 3294 Life Forms
N give you a string, then you want to find more than half of what the longest string of consecutive public string Yes. Suffix array dichotomous answer
Solution to a problem link: Click here
POJ1743Musical Theme
Seeking a sequence that satisfies the longest subtraction same two non-overlapping sequences. Unexpectedly a suffix array, first pre-differencing sequence, as long as required and then complete the longest find two identical subsequences like,
Solution to a problem link: Click here
POJ3261 Milk Patterns
It requires at least k times the overlapping length of the longest substring, the suffix array according to packet ordering height array, and satisfies the condition group of elements => k a is the answer.
Solution to a problem link: Click here
Trie
HDU 4099 Revenge of Fibonacci
Give you a string, find the smallest index Fibonacci numbers deed, so the string is a prefix that Fibonacci numbers this deed. The deed that number from 0 to 99999 Fibonacci into the dictionary tree, save only the first 40, and then look.
Solution to a problem link: Click here
HDU 1251 statistical problem
The statistics of the number of characters to a string prefixed by the number of words (the word itself is its own prefix). Array to add a sum to a node (the node to the end of the string as a prefix) are stored.
Solution to a problem link: Click here
HDU4825 Xor Sum
Looking with a different number or maximum number of results in a set of numbers.
Straight template, the number of array 01 are inserted into the dictionary tree, for every number query.
Solution to a problem link: Click here
HDU5536 Chip Factory
Finding the maximum value (s [i] + s [j]) ^ s [k] in an array, where i, j, k are different. 01 trie difficulty is that different judgments, where we can, first remove the x and y in the tree in the query dictionary 01 x and y and before, after other inquiries plus.
Solution to a problem link: Click here
BZOJ 4260 Codechef REBXOR
N give you the number, so that you seek the maximum of two disjoint interval or after and exclusive elements, and 01 trie operation of the interval.
Solution to a problem link: Click here
HDU 6096 String
Meaning of the title is a string to n, m times and then query each query has given prefix and suffix strings given how many. When construction of trie cross-built query time as well.
Solution to a problem link: Click here
AC automaton
Luo Gu P3796 [template] AC automaton (enhanced version)
Found that the highest number of female string substring appears, there are more on the order of input output, AC automaton enhanced version of the template can be used as a very good template to use
Solution to a problem link: Click here
Estimated 3228 Searching the String
N give you a template string and a text string, you ask these template strings appear in the text string up to many times. Template string may be repeated, and there are two types of template string, beginning to write two query functions, but only need to carefully think about a sub-array string length records are enough to determine the definition.
Solution to a problem link: Click here
HDU3065 viruses continued in
Give you a number of different templates and a text string. String to ask you each template are respectively the emergence of this text many times? And above that question and less a similar operation.
Solution to a problem link: Click here
HDU2457DNA repair
Give you the N template string, and give you a text string, and now ask you this text strings least need to change a few characters in order that it does not contain any template string, did not think AC automaton hindsight explanations to understand the use of DP thoughts + AC automaton
Solution to a problem link: Click here
Also HDU2296
M words to you constitute a dictionary, each word has a weight (and now you want to construct a N does not exceed the length of the string, the string so that the maximum weight. If multiple answers appear, or AC and automatic machine Together with the DP, the sum of weights to be recorded and that a maximum selection.
Solution to a problem link: Click here
HDU2825 Wireless Password
You now infer a length == n S consisting of a string of small letters how many ways the composition. S wherein the dictionary comprises at least one set of k words. And binding or DP, or the need to use an array of match.
Solution to a problem link: Click here
Treap:
POJ3481 Double Queue
There are n customers, each customer has a priority, we need three operations
1 XY ID is added to X, Y to priority customers
2 extract the maximum priority of the customer
3 extracted priority smallest customers
Using the priority queue, then simpler, the basic operation used Treap:
Solution to a problem link: Click here
POJ 2985 The k-th LargestGroup
Several groups, can be combined group, and then query the K-large team. Treap the basic operation.
Solution to a problem link: Click here
POJ2761 Feed the dogs
K-range large number of queries, this is not the total number of queries, each query interval is not the same. Each deleted beyond the range, not within range plus, find a small value of k
Solution to a problem link: Click here
BZOJ1503 depressed teller
Four operations, and then query the first few ranking of wages is. Treap will brush a question, adding that the operation is a delete operation of the entire number.
Solution to a problem link: Click here
Tree chain split
Bare tree chain split title, the template can be modified to change the price, to help understand the template ..
Solution to a problem link: Click here
Codeforces-343D Water Tree
Given a tree having N points, number 1 is the root node. There are three kinds of operation, the split tree chains are more basic problem.
Solution to a problem link: Click here
Chairman of the tree:
HDU 4471 Super Mario
Meaning of the title is the number n, the m ask you, then ask each to l, r, k r means that the inquiry into how a few lll smaller than k.
Chairman slightly deformed tree template.
Solution to a problem link: Click here
2019ICPC Nanchang J Invitational title Distance on the tree
Question is intended to n points, n-1 edges, and each edge of its own weight, m a query, each interrogation point is from one to another to meet the number of a point on the path weights is not more than k how many sides. '
This is the chairman of tree advanced plus the LCA.
Solution to a problem link: click here '