For an -order permutation , we set up an undirected simple graph with vertices numbered from to .
We create an edge between each vertice and the nearest vertices in each side which correspond a greater (or less) value than .
Formally,in this graph, , the edge exists iff at least one of the following four conditions hold:
, and no exists such that ;
, and no exists such that ;
, and no exists such that ;
, and no exists such that .
For a segment , define its corresponding permutation as an -order permutation with the same relative orders of elements as ; that is, for all , the boolean value is the same as the boolean value .
For instance, for the permutation , is a permutation of length with the same relative orders of elements as , i.e. .
The chromatic number of an undirected graph is the smallest number of colors needed to give each vertex a color such that every edge connects two vertices with different colors. We call this .
Given a permutation of length , please find the chromatic number of .
Additionally, please answer queries in the form of asking for: the greatest chromatic number among those of all corresponding permutations of each subsegment of , ; and the number of subsegment that achieve this maximum number .
(Formally,for each given ,,calculate the maximum possible value of ,called ,and .)
输入格式
第一行一个正整数 。
第二行 个正整数 。
第三行一个整数 。
接下来 行每行两个正整数 表示一组询问。
The first line contains a positive integer .
The second line contains positive integers .
The third line contains an integer .
The following lines each contains two positive integers , denoting a query.
输出格式
输出共 行,第一行一个正整数表示 的染色数,接下来每行两个整数 。
Output contains lines in total. The first one should contain a positive integer denoting the chromatic number of , followed by lines each containing two integers for each query.
样例
样例输入
6
1 4 5 3 6 2
5
1 6
1 3
2 5
2 6
3 3
样例输出
4
4 1
2 3
3 3
3 6
1 1
样例解释
下图描述 及一种染色方案:
Sample Input
6
1 4 5 3 6 2
5
1 6
1 3
2 5
2 6
3 3
Sample Output
4
4 1
2 3
3 3
3 6
1 1
Sample Explanation
The following picture describes and a way of coloring:
数据范围与提示
对于所有数据,。
详细的数据限制及约定如下(留空表示和上述所有数据的约定相同):
Subtask #
分值(百分比)
-
-
For all test cases, .
Detailed constraints and hints are as follows (blank grids denote the same constraints as mentioned above):