HDU 4691 Front Compression [后缀数组] [LCP]

该博客讨论了前缀压缩算法,这是一种节省存储空间的压缩方法。通过记录共同前缀及其长度来减少重复数据。文章给出了一个示例,并提出了一道编程题目,要求根据输入的子字符串计算原始大小和压缩后的大小。解决方案涉及使用后缀数组和最短公共前后缀(LCP)的概念,可以利用RMQ(Range Minimum Query)和稀疏表来高效计算。
摘要由CSDN通过智能技术生成

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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值