What do a Longest Increasing Subsequence and a Longest Decreasing Subsequence Know About Each Other?

As a kind of converse of the celebrated Erdős-Szekeres theorem, we present a necessary and sufficient condition for a sequence of length n to contain a longest increasing subsequence and a longest decreasing subsequence of given lengths x and y, respectively.


Introduction
In 1935, Hungarian mathematicians Paul Erdős and George Szekeres proved a celebrated theorem, which is now a classic, on relations between lengths of a sequence and its increasing (decreasing) subsequence [2].and x 1 , x 2 , • • • , x n is a sequence of real numbers.Then this sequence contains a monotonic increasing (decreasing) subsequence of a + 1 terms or a monotonic decreasing (increasing) subsequence of b + 1 terms.
More than 85 years have passed since then, and a whole subarea of combinatorics has grown up from the Erdős-Szekeres theorem.Even today we cannot fully appreciate the significance of this theorem, see, for instance, [1,3,4,6,7,8,9].
The main goal of this paper is to describe the complete family of constraints on the lengths of a sequence, its longest increasing subsequence, and its longest decreasing subsequence.

Main Results
Theorem 2.1.There exists a sequence T of length n > 1 containing a longest increasing subsequence of length x = lis(T ) > 1 and a longest decreasing subsequence of length y = lds(T ) > 1 if and only if the numbers x, y and n satisfy the following conditions: x • y ≥ n (*) Proof.First, we prove the necessity of the conditions (*) and (**).
Necessity of the condition (*) immediately follows from the theorem of Erdős-Szekeres.Assume that the condition (*) is not satisfied, i.e. x • y ≤ n − 1, then, according to the Erdős-Szekeres theorem, the sequence T of length n contains a monotone increasing subsequence of the length x + 1 or a monotone decreasing subsequence of the length y + 1 , which contradicts the hypothesis of the theorem.The violation of the condition (**) makes impossible the existence of two subsequences with specified lengths, one of which increases, while the other decreases.In fact, these two subsequences can have no more than one element in common; that is, the sum of their lengths should not exceed n + 1.
Sufficiency.Assume that x • y ≥ n and x + y ≤ n + 1, and build a sequence T of length n, such that x = lis(T ), y = lds(T ).This sequence is built according to the following scheme.We take a sequence of n natural numbers 1, 2, • • • , n and divide it into x groups, in such a way that T = Concatenation(T 1 , T 2 , • • • , T x ) and satisfies the following conditions: 1.The numbers in each group are arranged in decreasing order.2. All the numbers of a subsequent group are greater than all the numbers of a preceding group.3. The first group consists of y elements: y, y−1, y−2, • • • , 1, which is possible by the condition y < n. 4. We divide the remaining n − y elements into x − 1 groups as follows.Let . The first r groups represent decreasing subsequences T 2 , ..., T r+1 of the length p + 1: The last x − r − 1 groups represent decreasing subsequences T r+2 , ..., T x of length p.(In case of r = 0, all x−1 decreasing subsequences have the length p): The algorithm building the sequence T and the proof of its correctness are given below.Before passing to the proof of the sufficiency, we prove the following.
Claim 2.2.At the partition of n−y elements into x−1 groups satisfying Conditions 1-4, the number of elements in each group does not exceed y.
Since 0 ≤ r < x − 1, while p and y are positive integers, the number of elements in a longest group p + 1 ≤ y if r > 0. In the case of r = 0 all the x − 1 groups are of the same length p and p ≤ y.Now we prove the sufficiency of the conditions (*) and (**) under the assumption that the sequence T is built and satisfies Conditions 1-4.
First, we prove that the group named LDS is a longest decreasing subsequence of T .Actually, the number of groups is equal to x.The number of elements in the first group is equal to y.By Claim 2.2, the number of elements in any other group does not exceed y.Besides, by the fact that the elements of each of x groups are arranged in decreasing order, and for every group all the elements of the subsequent group are greater than all the elements of this group, the longest decreasing subsequence can be made up from elements of one group only, and a largest group is the first one, its length being y.Now we build a sequence and name it LIS , which includes one element of each of x groups, and prove that it is, actually, the longest increasing subsequence of T .In fact, since the elements of each of x groups are arranged in decreasing order, the subsequence LIS can include no more than one element of each group.And since for every group all the elements of the subsequent group are greater than all the elements of this group, the subsequence LIS is an increasing sequence that has the maximal possible length equal to x.That is, LIS is a longest increasing subsequence of T .For example, LIS may be composed of the first elements of each group.

Building Sequence T
Input: Integer numbers n > 1, x > 1, y > q, which satisfy conditions (*), (**).Output: The procedure of producing the desired sequence T is as follows.In Lines 5-8 we build the first group of numbers representing a decreasing subsequence of the length y, whose elements are the numbers y, y − 1, y − 2, • • • 1.In Lines 9, 10 the numbers p = n − y (x − 1 and r = (n − y)mod(x − 1) are computed.In Lines 11-17 we build r groups consisting of p + 1 elements, and in Lines 18-24 we build x − r − 1 groups consisting of p elements.In each group the elements are arranged in decreasing order, and for all groups each number of a subsequent group is greater than all the numbers of this group.Therefore, T is the desired sequence.for i ← y to 1 step=-1 do 6: end for for i ← 1 to r step=1 do 12: for j ← p+1 to 1 step=-1 do Remark 2.7.There are other methods of building sequences satisfying the conditions (*) and (**).For instance, the sequence 1, 2, • • • , n can be divided into y groups as follows: 1. Numbers in each group are arranged in the increasing order.
2. All the numbers of a subsequent group are smaller than all the numbers of a preceding group.As a result of Algorithm 2.3, we obtain a sequence T , satisfying Conditions 1-4.Also, we have shown that this sequence contains a longest increasing subsequence of length x and a longest decreasing subsequence of length y.This allows us to formulate the following: Theorem 2.8.Algorithm 2.3 constructs the sequence T , such that x = lis(T ), y = lds(T ).Its complexity is O(n).

Conclusions
A set of integer points in a plane with the coordinates (x, y) satisfying the conditions (*) and (**) is located in the area between a straight line x + y = n + 1 and a hyperbola x • y = n (Figure 1).The number f (n) of such points is defined as the difference between the number of integer points with positive coordinates located between the straight line x + y = n + 1 and coordinate axes and the number of integer points with positive coordinates located between the hyperbola x • y = n and the coordinate axes.The number of integer points located between the straight line x+y = n+1 and the coordinate axes equals n(n + 1) ÷ 2, and the number of integer points located between the hyperbola x • y = n and the coordinate axes equals where τ(i) is the divisor function computing the number of divisors of i, and D(n) is the divisor summatory function [5].Hence, the number of integer points satisfying the conditions (*) and (**) equals A simple and efficient method of computing D(n) with the complexity O( √ n) is known: A question of improving on the efficiency of D(n) computation remains.