Front compression
翻译见后
Description
Front compression is a type of delta encoding compression algorithm whereby common prefixes and their lengths are recorded so that they need not be duplicated. For example:
The size of the input is 43 bytes, while the size of the compressed output is 40. Here, every space and newline is also counted as 1 byte.
Given the input, each line of which is a substring of a long string, what are sizes of it and corresponding compressed output?
Input
There are multiple test cases. Process to the End of File.
The first line of each test case is a long string S made up of lowercase letters, whose length doesn’t exceed 100,000. The second line contains a integer 1 ≤ N ≤ 100,000, which is the number of lines in the input. Each of the following N lines contains two integers 0 ≤ A < B ≤ length(S), indicating that that line of the input is substring [A, B) of S.
Output
For each test case, output the sizes of the input and corresponding compressed output.
Sample Input
frcode
2
0 6
0 6
unitedstatesofamerica
3
0 6
0 12
0 21
myxophytamyxopodnabnabbednabbingnabit
6
0 9
9 16
16 19
19 25
25 32
32 37
Sample Output
14 12
42 31
43 40
翻译:
题意:
根据图中的方法压缩输入的字符串,压缩后为可匹配的长度空格与剩余的字符串,输出未压缩字符串的长度与压缩后的长度,空格与提行也算。
我们来模拟一个样例:
frcode
2
0 6
0 6
则第一个输入串为frcode,第二个也为frcode,原串为
frcode
frcode
它的压缩后结果为
0 frcode
6
于是它的原长为14,压缩后为12。
那么我们发现原长十分好算,即每次的长度相加即可,而压缩后的长度就可以有后缀数组来解决(这个题数据水,暴力也能过)。最后注意一下精度就AC~(≧▽≦)/~啦啦啦。
附代码: