地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3961

题目:

ACM (ACMers' Chatting Messenger) is a famous instant messaging software developed by Marjar Technology Company. To attract more users, Edward, the boss of Marjar Company, has recently added a new feature to the software. The new feature can be described as follows:

If two users, A and B, have been sending messages to each other on the last mconsecutive days, the "friendship point" between them will be increased by 1 point.

More formally, if user A sent messages to user B on each day between the (i - m + 1)-th day and the i-th day (both inclusive), and user B also sent messages to user A on each day between the (i - m + 1)-th day and the i-th day (also both inclusive), the "friendship point" between A and B will be increased by 1 at the end of the i-th day.

Given the chatting logs of two users A and B during n consecutive days, what's the number of the friendship points between them at the end of the n-th day (given that the initial friendship point between them is 0)?

Input

There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 10), indicating the number of test cases. For each test case:

The first line contains 4 integers n (1 ≤ n ≤ 109), m (1 ≤ m ≤ n), x and y (1 ≤ xy ≤ 100). The meanings of n and m are described above, while x indicates the number of chatting logs about the messages sent by A to B, and y indicates the number of chatting logs about the messages sent by B to A.

For the following x lines, the i-th line contains 2 integers lai and rai (1 ≤ la,i ≤ rai ≤ n), indicating that A sent messages to B on each day between the lai-th day and the rai-th day (both inclusive).

For the following y lines, the i-th line contains 2 integers lbi and rbi (1 ≤ lb,i ≤ rbi ≤ n), indicating that B sent messages to A on each day between the lbi-th day and the rbi-th day (both inclusive).

It is guaranteed that for all 1 ≤ i < xrai + 1 < lai + 1 and for all 1 ≤ i < yrbi + 1 < lbi + 1.

Output

For each test case, output one line containing one integer, indicating the number of friendship points between A and B at the end of the n-th day.

Sample Input

2
10 3 3 2
1 3
5 8
10 10
1 8
10 10
5 3 1 1
1 2
4 5

Sample Output

3
0

Hint

For the first test case, user A and user B send messages to each other on the 1st, 2nd, 3rd, 5th, 6th, 7th, 8th and 10th day. As m = 3, the friendship points between them will be increased by 1 at the end of the 3rd, 7th and 8th day. So the answer is 3.

思路:手速题+4

暴力n^2匹配就好

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
#define ll first
#define rr second
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int n,m,na,nb;
PII ta[K],tb[K]; int main(void)
{
int t;cin>>t;
while(t--)
{
int ans=;
cin>>n>>m>>na>>nb;
for(int i=;i<=na;i++)
scanf("%d%d",&ta[i].ll,&ta[i].rr);
for(int i=;i<=nb;i++)
scanf("%d%d",&tb[i].ll,&tb[i].rr);
for(int i=;i<=na;i++)
{
for(int j=;j<=nb;j++)
if(tb[j].ll>=ta[i].ll && ta[i].rr>=tb[j].ll)
{
int tmp=min(ta[i].rr,tb[j].rr)-tb[j].ll+;
ans+=tmp>=m?tmp-m+:;
}
else if(tb[j].rr>=ta[i].ll && ta[i].rr>=tb[j].rr)
{
int tmp=tb[j].rr-max(ta[i].ll,tb[j].ll)+;
ans+=tmp>=m?tmp-m+:;
}
else if(ta[i].ll>=tb[j].ll && ta[i].rr<=tb[j].rr)
{
int tmp=ta[i].rr-ta[i].ll+;
ans+=tmp>=m?tmp-m+:;
}
}
printf("%d\n",ans);
}
return ;
}

2017浙江省赛 D - Let's Chat ZOJ - 3961的更多相关文章

  1. 2017浙江省赛 H - Binary Tree Restoring ZOJ - 3965

    地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3965 题目: iven two depth-first-search ...

  2. 2017浙江省赛 E - Seven Segment Display ZOJ - 3962

    地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目: A seven segment display, or ...

  3. 2017浙江省赛 A - Cooking Competition ZOJ - 3958

    地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3958 题目: "Miss Kobayashi's Drag ...

  4. 2017浙江省赛 C - What Kind of Friends Are You? ZOJ - 3960

    地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3960 题目: Japari Park is a large zoo ...

  5. 2017浙江省赛 B - Problem Preparation ZOJ - 3959

    地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3959 题目: It's time to prepare the pr ...

  6. (2017浙江省赛E)Seven Segment Display

    Seven Segment Display Time Limit: 2 Seconds      Memory Limit: 65536 KB A seven segment display, or ...

  7. Let's Chat ZOJ - 3961

    ACM (ACMers' Chatting Messenger) is a famous instant messaging software developed by Marjar Technolo ...

  8. 2017 湖南省赛 K Football Training Camp

    2017 湖南省赛 K Football Training Camp 题意: 在一次足球联合训练中一共有\(n\)支队伍相互进行了若干场比赛. 对于每场比赛,赢了的队伍得3分,输了的队伍不得分,如果为 ...

  9. ZOJ 3879 Capture the Flag 15年浙江省赛K题

    每年省赛必有的一道模拟题,描述都是非常的长,题目都是蛮好写的... sigh... 比赛的时候没有写出这道题目 :( 题意:首先输入4个数,n,q,p,c代表有n个队伍,q个服务器,每支队伍的初始分数 ...

随机推荐

  1. Hibernate_day04--课程安排_Hibernate查询方式_对象导航查询_OID查询

    Hibernate_day04 上节内容 今天内容 Hibernate查询方式 对象导航查询 OID查询 HQL查询 查询所有 条件查询 排序查询 分页查询 投影查询 聚集函数使用 QBC查询 查询所 ...

  2. 使用ProcDump工具抓取dump

    首先得到要抓取的进程号 cd %windir%\syswow64\inetsrvappcmd list wp得到pid之后, 在任务管理器里发现w3wp.exe的CPU总在49%-60%左右, 间歇性 ...

  3. ArcGIS 同一要素图层合并

  4. 开发环境eclipse for Mac 下的常用快捷键汇总(基本参照Win系,将Ctrl换为Command)

    最近迁移开发环境到Mac下,在豆瓣看到一个常用快捷键,去掉废话直接上干货 Command + O:显示大纲 Command + 1:快速修复 Command + D:删除当前行 Command + O ...

  5. keystore是个嘛东西

    不管是QQ,还是微信,还是支付,涉及到第三方的都的用这个玩意,有时候找不对很坑的 首先我们要区分jks, app,keystore(新建keystoer的文件new就可以了)再进行下一步操作 Ecli ...

  6. 获取UIWebView的内容高度

    本文转载至 http://i.cnblogs.com/EditPosts.aspx?opt=1   #pragma mark - UIWebview delegete - (void)webViewD ...

  7. dubbo项目实战代码展示

    最近公司项目使用dubbo服务,于是就去网上搜索关于dubbo的相关资料,真的很多,但是对于很多人并不是很了解框架或者 不是太适合新手的片段代码,于是我就根据项目的相关内容把dubbo部分单独切出来, ...

  8. 非IE图片上传预览

    $("#uploadFiles").change(function (e) {                if (e.target.files) {               ...

  9. iOS 界面翻转切换动画

    [UIView  beginAnimations:nil context:NULL]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [ ...

  10. Python--进阶处理5

    # 使用路径名来获取文件名,目录名,绝对路径等import ospath = r'F:\myProject\lean\a'# Get the last component of the pathbas ...