您的位置:首页 > 其它

zoj 3518

2011-07-24 22:52 441 查看
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3518
Xiao Ming has two paper tapes with the same length. He wants to use them to hang some weight. But XiaoMing finds that the paper tape may have some damaged areas, which will make the tape easier to be broken. For clever Xiao Ming, he sticks these two tapes up from the start point to the end point.
But there is a new problem, after paste, in some place the tape may exist hidden flaw. Hidden flaw means at this place, one of the two tape has damaged areas before paste, but after paste, this kind of damaged areas may be difficult to be found, otherwise, if both of the tapes at some places have damaged areas, they are still visible after pasting.
After this paste work, his father goes back home and finds XiaoMing's perfect work. His father finds damaged areas which are still visible on the new tape and fixs it. Oh, what an adorable father he is!
Because of the hidden damaged areas, there is still unsafe factor. We define the "Unsafe Factor" as the longest length of the successive hidden damaged areas.
Your task is to calculate the "Unsafe Factor".
NOTICE: the damaged areas are regarded as a point on the tape.

Input

The input file contains several test cases (no more than 20).
For each case, the first line contains three integers L, n1, n2 (0 < L ≤ 10000000, 0 ≤ n1, n2 ≤ 100000) which indicate the length of the tape, the number of the damaged area intervals for tape 1 and the number of the damaged area intervals for tape 2. Then follows n1 and n2 lines. The format of each line is two integer "x y" (0 ≤ x ≤ y < L), indicate there are damaged areas at x to y (x, x+1, x+2, x+3, ... y point have a damaged area).
We ensure that each damaged area is told only once in the input file for each case.

Output

For each case, output the "Unsafe Factor" in a single line.

Sample Input

10 3 2
1 4
5 6
8 9
1 1
6 7

Sample Output

4
大概意思就是说给你一条线段长L(<=10^7),两次操作,第一次操作将n个区间(区间互不相交)标记为1 ,第二次操作将m个区间标记为2,求一个最长的区间只出现标记1或只出现标记2。(n,m<=10^5)
分析:估计今天是和if else结缘了,比赛的时候纯模拟区间相交,if else 写到想吐。好的做法是先离散化,对第一次操作的n个区间按左端点排序,然后扫描标记,再对第二次操作的m个区间同样的操作,最后扫描离散数组里只标记了一次的线段,统计
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: