Front compression
Time Limit: 5000MS
Memory Limit: 102400KB
64bit IO Format: %I64d & %I64u
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
Source
2013 Multi-University Training Contest 9
题目很明确,就是求当前字符串与上一个字符串的LCP长度
由于是在同一个字符串里的字串,可以使用后缀数组求解。
又因为后缀 i 和后缀 j 的LCP长度为 RMQ(height,rank[i]+1,rank[j]),当然 rank[i] < rank[j] ,那么用Sparse Table 完美解决。
不过要注意query时 , i j 的rank大小不确定, 要在函数里面+1!!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<iomanip>
#include<ctime>
#include<climits>