CF469B.Chat Online
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little X and Little Z are good friends. They always chat online. But both of them have schedules.
Little Z has fixed schedule. He always online at any moment of time between _a_1 and _b_1, between _a_2 and _b_2, ..., between a__p and b__p (all borders inclusive). But the schedule of Little X is quite strange, it depends on the time when he gets up. If he gets up at time 0, he will be online at any moment of time between _c_1 and _d_1, between _c_2 and _d_2, ..., between c__q and d__q (all borders inclusive). But if he gets up at time t, these segments will be shifted by t. They become [c__i + t, d__i + t] (for all i).
If at a moment of time, both Little X and Little Z are online simultaneosly, they can chat online happily. You know that Little X can get up at an integer moment of time between l and r (both borders inclusive). Also you know that Little X wants to get up at the moment of time, that is suitable for chatting with Little Z (they must have at least one common moment of time in schedules). How many integer moments of time from the segment [l, r] suit for that?
小 X 和小 Z 是好朋友,他们经常在线聊天。但两人都有自己的日程安排。
小 Z 的日程是固定的:他在时间区间 [a1,b1]、[a2,b2]、……、[ap,bp](所有端点均包含在内)的任意时刻都在线。
而小 X 的日程则非常特殊,它取决于他起床的时间。若他在时刻 0 起床,则他在时间区间 [c1,d1]、[c2,d2]、……、[cq,dq](所有端点均包含在内)的任意时刻都在线;若他在时刻 t 起床,则这些区间将整体向右平移 t,即变为 [ci+t,di+t](对所有 i)。
若在某一时刻,小 X 和小 Z 同时在线,则他们可以愉快地在线聊天。已知小 X 可以在整数时刻 t 起床,且 t 的取值范围为 [l,r](两端点均包含在内)。此外,小 X 希望选择一个能与小 Z 成功聊天的起床时刻(即两人的在线时间至少存在一个公共时刻)。问:在区间 [l,r] 中,有多少个整数时刻 t 满足该条件?
输入格式
The first line contains four space-separated integers p, q, l, r (1 ≤ p, q ≤ 50; 0 ≤ l ≤ r ≤ 1000).
Each of the next p lines contains two space-separated integers a__i, b__i (0 ≤ a__i < b__i ≤ 1000). Each of the next q lines contains two space-separated integers c__j, d__j (0 ≤ c__j < d__j ≤ 1000).
It's guaranteed that b__i < a__i + 1 and d__j < c__j + 1 for all valid i and j.
第一行包含四个以空格分隔的整数 p、q、l、r(1≤p,q≤50;0≤l≤r≤1000)。
接下来的 p 行,每行包含两个以空格分隔的整数 ai、bi(0≤ai<bi≤1000)。再接下来的 q 行,每行包含两个以空格分隔的整数 cj、dj(0≤cj<dj≤1000)。
保证对所有合法的 i 和 j,均有 bi<ai+1 且 dj<cj+1。
输出格式
Output a single integer — the number of moments of time from the segment [l, r] which suit for online conversation.
输出一个整数——即区间 ([l, r]) 中适合进行在线聊天的时间点的个数。
输入输出样例
输入#1
1 1 0 4 2 3 0 1
输出#1
3
输入#2
2 3 0 20 15 17 23 26 1 4 7 11 15 17
输出#2
20
输入解题思路,AI测评打分。不知道怎么写?