创想实验室
我们都是梦想家

Chat Online

描述

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 ap and bp (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 cq and dq (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?

输入

The first line contains one interger $T$($1 \leq T \leq 30$) which indicates the case number.
For each test case:
The first line contains four space-separated integers $p, q, l, r$ ($1 \leq p, q \leq 50; 0 \leq l \leq r \leq 1000$).
Each of the next p lines contains two space-separated integers ai, bi ($0 \leq ai < bi \leq 1000$). Each of the next q lines contains two space-separated integers $c_j$, $d_j$ ($0 \leq cj < dj \leq 1000$).
It’s guaranteed that $b_i < a_i + 1$ and $d_j < c_j + 1$ for all valid $i$ and $j$.

输出

Output a single integer — the number of moments of time from the segment $[l, r]$ which suit for online conversation.

样例输入

 

样例输出

 

题解

这题其实就是数学题,看懂就会做了。。。。。

代码

 

网站所发布的代码已提交通过,代码可能经过修改防止抄袭,未经允许不得转载:创想实验室 » Chat Online
分享到: 更多 (0)

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    good a blog!

    jie.la7个月前 (03-16)回复