#P4747. [CERC2017] Intrinsic Interval
[CERC2017] Intrinsic Interval
题目描述
Given a permutation of integers through , an interval in is a consecutive subsequence consisting of consecutive numbers. More precisely, for indices and where , the subsequence is an interval if sorting it would yield a sequence of consecutive integers.
For example, in permutation , the subsequence is an interval (it contains the numbers through ) while is not.
For a subsequence its intrinsic interval is any interval that contains the given subsequence and that is, additionally, as short as possible. Of course, the length of an interval is defined as the number of elements it contains.
Given a permutation and of its subsequences, find some intrinsic interval for each subsequence.
输入格式
The first line contains an integer — the size of the permutation . The following line contains different integers — the permutation itself.
The following line contains an integer — the number of subsequences. The of the following lines contains integers and — the endpoints of the subsequence.
输出格式
Output lines. The line should contain two integers and where — the endpoints of some intrinsic interval of the subsequence .
题目大意
题目描述
对于正整数 的一个排列 ,若它的一个子串 排序后是连续正整数,则称 是一个“区间”。例如对排列 ,子串 是一个“区间”(因为它包含 ), 则不是。
一个子串的“本征区间”是包含该子串的最短区间。“包含”是指:若 的本征区间是 ,则 。
给定一个排列 及其 个子串,求每个子串的“本征区间”。
输入格式
第一行一个整数 。
第二行 个整数,代表排列 。
第三行一个整数 。
此后 行,每行两个整数 ,代表子串 。
输出格式
输出 行,每行两个整数 ,代表子串对应的本征区间 。
7
3 1 7 5 6 4 2
3
3 6
7 7
1 3
3 6
7 7
1 7
10
2 1 4 3 5 6 7 10 8 9
5
2 3
3 7
4 7
4 8
7 8
1 4
3 7
3 7
3 10
7 10