当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2867:Where Are My Genes

题目描述
One way that scientists try to measure how one species evolved into another is to find out how the ancestor's genome changed into the other's. Closely related species have several genes in common and it turns out that a good way to compare them is comparing how the common genes changed place.

One of the most common mutations that change the order of a genomes' genes is the reversal. If we model a genome as a sequence of N genes with each gene being an integer from 1 to N, then a reversal is a mutation that changes the genome by reverting the order of a block of consecutive genes. A reversal can be described by two indexes (i, j), 1 <= i <= j <= N, indicating that it reverts the order of the genes within indexes from i to j. So, when it is applied to a genome [g1, ..., gi-1, gi, gi+1, ..., gj-1, gj , gj+1, ..., gN], we obtain the genome [g1, ..., gi-1, gj, gj-1, ..., gi+1, gi, gj+1, ..., gN]. As an example, the reversal (3, 6) applied to the genome [1, 2, 3, 4, 5, 6, 7] gives [1, 2, 6, 5, 4, 3, 7]. If after that the reversal (1, 3) is applied, we obtain the genome [6, 2, 1, 5, 4, 3, 7].

A scientist studying the evolution of a species wants to try a series of reversals on its genome. Then he wants to query the final position of several genes. Would you take the challenge and help him?
输入解释
The input contains several test cases. The first line of a test case contains one integer N indicating the number of genes in the genome (1 <= N <= 50000). You may assume that the initial order of the genes is the sequence of integers from 1 to N in increasing order. The second line of a test case contains one integer R (0 <= R <= 1000) indicating the number of reversals to be applied to the genome. Then R lines follow, each containing two integers i, j (1 <= i <= j <= N), separated by a single space, indicating the two indexes that define the corresponding reversal. After the description of the reversals there is a line containing one integer Q (0 <= Q <= 100), indicating the number of queries for genes, followed by Q lines, where each line contains an integer representing a gene whose final position you must determine.
The end of input is indicated by N = 0.
输出解释
For each test case in the input your program must produce Q+1 lines of output. The first line must contain the string "Genome " followed by the number of the test case. The following Q lines must contain one integer each representing the answers of the queries.
输入样例
9
1
3 6
4
1
3
5
1
5
2
1 2
1 5
2
5
2
0
输出样例
Genome 1
1
6
4
1
Genome 2
1
5

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 South America 2005

源链接: POJ-2867

最后修改于 2020-10-29T06:46:17+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536