#P14109. [ZJCPC 2017] Card Game

[ZJCPC 2017] Card Game

题目描述

Alice and Bob are playing games again. This game has nothing to do with stones. It is actually a card game.

There are nn cards on the table, each with two integers (one is red, and the other one is blue) written on it. At the beginning of each round, two integers, LL and RR, will be given. Alice will pick an integer xx such that LxRL \le x \le R and tell her choice to Bob. After knowing the integer xx, Bob will then choose a card from the table. The score of this round will be equal to rx+brx+b, where rr is the red integer on the chosen card and bb is the blue integer on the chosen card.

Both Alice and Bob are free to check the cards on the table and the integers written on them before they make their decisions.

To make the game more interesting, some changes can be made before a certain round. There are two possible changes:

  • Add another card with a red integer and a blue integer written on it onto the table.
  • Remove a card from the table.

Alice wants to maximize the score of each round, while Bob wants to minimize it. If both of them play the game optimally, can you find out the final score for each round?

输入格式

There are multiple test cases. The first line of input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains two integer nn (1n5×1041 \le n \le 5 \times 10^4) and qq (1q5×1041 \le q \le 5 \times 10^4), indicating the number of cards on the table at the beginning, and the number of operations.

For the following nn lines, the ii-th line contains two integers rir_i and bib_i (109ri,bi109-10^9 \le r_i, b_i \le 10^9), indicating that initially there is a card with a red integer rir_i and a blue integer bib_i written on it on the table.

For the following qq lines, each line contains three integers opop (0op20 \le op \le 2), aa and bb (109a,b109-10^9 \le a, b \le 10^9).

  • If opop equals 00, you are asked to calculate the final score of a round, where L=aL = a and R=bR = b is given. It's guaranteed that aba \le b on this occasion.
  • If opop equals 11, a card with a red integer aa and a blue integer bb written on it will be put onto the table.
  • If opop equals 22, a card with a red integer aa and a blue integer bb written on it will be removed from the table. It's guaranteed that this card exists on the table. If there are multiple cards on the table which satisfy the condition, only one of them will be removed.

It's guaranteed that neither the sum of nn nor the sum of qq over all test cases will exceed 2×1052 \times 10^5.

We kindly remind you that this problem contains large I/O file, so it's recommended to use a faster I/O method. For example, you can use scanf/printf instead of cin/cout in C++.

输出格式

For each operation 00 output one line, indicating the final score of that round.

2
2 7
-1 2
2 3
0 -1 1
2 -1 2
0 -1 1
2 2 3
1 1 2
1 -2 -1
0 -1 1
2 3
1 1
1 1
0 1 3
2 1 1
0 1 3
2
5
1
4
4