#abc365g. G - AtCoder Office
G - AtCoder Office
Score : points
问题陈述
个人在AtCoder办公室工作。
办公室记录了进出情况,自记录开始以来共有次进出。
第次()记录由一对整数表示,表示在时间,第个人要么进入办公室(如果他们在外面),要么离开办公室(如果他们在里面)。
已知所有人员在记录开始时都在办公室外面,现在他们也都在外面。
以以下格式回答个查询。
对于第个()查询,你将得到一对整数。找出自记录开始以来,第个人和第个人同时在办公室内的时间段的总长度。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
people work at the AtCoder office.
The office keeps records of entries and exits, and there have been entries and exits since the records began.
The -th record is represented by a pair of integers , indicating that at time , the -th person either entered the office if they were outside, or exited the office if they were inside.
It is known that all people were outside the office at the beginning of the records, and they are outside now.
Answer queries in the following format.
For the -th query, you are given a pair of integers . Find the total length of the periods during which both the -th and -th persons were inside the office since the records began.
Constraints
- For every , the number of indices such that is even.
- All inputs are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer to the -th query.
Sample Input 1
3 8
10 1
20 2
30 1
40 3
60 3
70 1
80 2
90 1
3
1 2
1 3
2 3
Sample Output 1
20
0
20
The following diagram shows the time each of the three people spent inside the office.
The answers to each query are as follows:
- The 1st and 2nd persons were both inside the office from time to time and from time to time . The lengths of these two periods are both , so print the total, which is .
- The 1st and 3rd persons were never inside the office at the same time, so print .
- The 2nd and 3rd persons were both inside the office from time to time . The length of this period is , so print .
Sample Input 2
10 20
10257 9
10490 4
19335 1
25893 5
32538 9
33433 3
38522 9
40629 9
42896 5
52106 1
53024 3
55610 5
56721 9
58286 9
63128 3
70513 3
70977 4
74936 5
79883 9
95116 9
7
1 3
3 9
1 9
4 9
1 5
5 9
3 5
Sample Output 2
18673
2107
15310
25720
17003
10317
16848