31 analog solution to a problem

A. math

Hit the wrong answers to the exam,
take gcd each $ a_i $ and k respectively made backpacks from 0 up to k.
But the complexity of the issue a bit, then made a sieve.
$ O (k sqrt (k) ) $ certain there is no problem, very good without special data structure under.
After the test was suddenly yourself a simple data hack out.
6 2
2 3
My program will output
5
0 2 3 4 5
but apparently 1 can be pieced out.
K $ positive solutions is obtained with all the $ a_i gcd.
The answer is k / gcd,
and the first term is zero tolerance of less than k, the number of columns for the last term gcd of arithmetic.
Correctness is obvious.


B. biology

All coordinates into the structure where,
in a row a value sequence,
direct $ O (n ^ 4) $ violent dp.

It is optimized to $ O (n ^ 2) $ or $ O (n ^ 2logn) $ can be had.
The third sub-section was observed, to obtain a nature:
a line can only be transferred from the former by its row.
The reason is that the b value is not negative, and the other is a distance between two points.
The answer will not go more than once deteriorated.
Observation continued to give further properties:
the vertical and horizontal distance between two points in a coordinate apart,
coming $ abs (x1-x2) + abs (y1-y2) $ split in a similar $ (x1 + y1) - ( x2 + y2) $ of four forms.
Distance between two points is not good maintenance can be converted off.
Only need to know the maximum value for each point in the four directions.
Tree-dimensional array can be maintained, complexity $ O (n ^ 2log ^ 2n ) $.

Why pay attention to the exact direction?
According to consider the fact that indeed needed.
In a question angel doll, the required minimum.
If we choose the wrong direction may cause the abs should take a positive value takes a negative, so the answer is smaller, it was wrong.
However, as the answer to this question in greater is better.
If you make some answers might make a smaller operation, it does not affect the final answer.
So directly to the maintenance Fenwick tree into four variables to maintain it.
This problem doing very bumpy in the examination room, a little violence of the dp, nausea split into data structures, eventually back of a very simple form.



C. english

Section title requested more intractable,
apparently enumerate a maximum where to find it decision about intervals.
I asked one of the first cut.
Obviously XOR bit processing, processing a prefix number 1 on every interval and to find.
Enumeration maximum, only 0 ^ 1 1 available directly find the interval would be finished.

The second question is also complicated,
due to the statistical program, apparently to maintain the trie.
To query interval can be persistent ah, it is not difficult to play.
Still enumerate the maximum,
if the maximum value of the left side of the interval is short, enumerator range on the left side, the right side of the query interval.
On the other hand the number on the right side of the interval to enumerate, query the left side of the interval.
On the test really have no idea how to construct a data card out of this algorithm (actually he did not), hit out.

The complexity of the evidence with the idea of the severity of his son.
Should first be noted that some properties:
obtaining about interval must satisfy
$ A [i] <A [L [i] -1] $
$ A [i] <A [R & lt [i] + 1'd] $
either take the i the decision interval J,
$ a [J] <a [I] $
an initial interval (1, n), and constantly looking for the maximum interval recursively to the left, may be formed in a binary tree.
So our algorithm is to constantly re-enumeration light query son son.
Obviously complexity is $ O (nlognlogmx) $.
The worst case is a complete binary tree.

If you think of the idea of positive solutions,
can also contribute directly to find the severity of his son, the questions do with heuristic merge the trie.



And AK, however very lucky.
T1 playing the wrong solution, T3 will not prove complexity.
T2 do very bumpy, and finally a little closer to a positive solution.

Guess you like

Origin www.cnblogs.com/skyh/p/11406835.html