地址: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. ChemDraw Pro绘制无环链结构的两种方法

    ChemDraw Pro 14是一款专门针对化学图形绘制而开发制作的编辑软件,是目前工科类常用的绘制化学结构工具,用于快速绘制常用的环结构组成.以下教程讲解ChemDraw Pro绘制无环链结构的两种 ...

  2. 转:解决Python2.7的UnicodeEncodeError: ‘ascii’ codec can’t encode异常错误

    操作SQL数据库,Python使用的是版本2.7,但是在运行的时候出现了异常错误UnicodeEncodeError:'ascii' codec can't encode characters in ...

  3. 学习《深入理解C#》—— 数据类型、排序和过滤 (第一章1.1---1.2)

    引言 在开始看这本书之前看过一些技术博客,填补自己对于一些知识点的不足.无意中发现了<深入理解C#>这本书,本书主要探讨C# 2.C# 3和C# 4的细节与特性,所以做了一下阅读笔记,欢迎 ...

  4. Spring_day02--log4j介绍_Spring整合web项目演示

    log4j介绍 1 通过log4j可以看到程序运行过程中更详细的信息 (1)经常使用log4j查看日志 2 使用 (1)导入log4j的jar包 (2)复制log4j的配置文件,复制到src下面 3 ...

  5. 剑指 offer set 23 n 个骰子的点数

    题目 把 n 个骰子扔到地上, 所有骰子朝上一面的点数之和为 s. 输入 n, 打印出 s 所有可能的值出现的概率. 思路 1. 基于递归的求解方法. 深度为 n 的 dfs, 相当于求全排列, 时间 ...

  6. ios开发--图文混排(富文本)

    最近准备接一个编辑类的app,所以就查了下相关的功能,并自己试验了下: /** iOS 6之前:CoreText,纯C语言,极其蛋疼 iOS 6开始:NSAttributedString,简单易用 i ...

  7. 部分常用dos命令

    Microsoft Windows XP [版本 ] (C) 版权所有 - Microsoft Corp. C:\Documents and Settings\Administrator>d: ...

  8. LeetCode-Water and Jug Problem

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. Struts2的默认拦截器执行顺序

    我们在写Struts2的时候package属性默认都是差不多这样吧 <package name="packageName" namespace="/" e ...

  10. Python全栈day13(作业讲解根据用户输入选择输出字典内容)

    题目,有一个动植物对应的字典内容如下,请根据用户输入列出对应的动物或者植物,实现字典三级菜单功能 dic = { "植物": {"草本植物": ["牵 ...