#P14103. [ZJCPC 2017] Let's Chat
[ZJCPC 2017] Let's Chat
题目描述
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, and , have been sending messages to on the last days, the "friendship point" between them will be increased by point.
More formally, if user sent messages to user on each day between the -th day and the -th day (both inclusive), and user also sent messages to user on each day between the -th day and the -th day (also both inclusive), the "friendship point" between and will be increased by at the end of the -th day.
Given the chatting logs of two users and during consecutive days, what's the number of the friendship points between them at the end of the -th day (given that the initial friendship point between them is )?
输入格式
There are multiple test cases. The first line of input contains an integer (), indicating the number of test cases. For each test case:
The first line contains four integers (), (), and (). The meanings of and are described above, while indicates the number of chatting logs about the messages sent by to , and indicates the number of chatting logs about the messages sent by to .
For the following lines, the -th line contains two integers and (), indicating that sent messages to on each day between the -th day and the -th day (both inclusive).
For the following lines, the -th line contains two integers and (), indicating that sent messages to on each day between the -th day and the -th day (both inclusive).
It is guaranteed that for all , and for all , .
输出格式
For each test case, output one line containing one integer, indicating the number of friendship points between and at the end of the -th day.
2
10 3 3 2
1 3
5 8
10 10
1 8
10 10
5 3 1 1
1 2
4 5
3
0
提示
For the first test case, user and user send messages to each other on the -st, -nd, -rd, -th, -th, -th, -th and -th day. As , the friendship points between them will be increased by at the end of the -rd, -th and -th day. So the answer is .