403100: GYM101005 C Wheat

Memory Limit:32 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Wheattime limit per test2.6 secondsmemory limit per test32 megabytesinputstandard inputoutputstandard output

Steven wants to start his own wheat farm. In order to do so, every land patch needs to meet some strict regulations regarding the pH and Feng Shui index. Luckily for him, he can change the value of the pH or Feng Shui index by one for one dollar.

Steven knows N types of land patches and their pH and Feng Shui indexes. Unfortunately, due to bad legislation, some patches can become forbidden and others can become permitted.

Steven must answer to three types of queries. What's the minimal cost to transform a land patch to a valid one? A land patch becomes forbidden, A land patch becomes permitted.

Input

The first line contains a positive integer N (1 ≤ N ≤ 250 000) - the number valid land patches in the beginning. The next N lines contain two positive integers p,  h ( - 228 ≤ p, h ≤ 228) - the pH index and the Feng Shui index of the land patch.

The next line contains a positive integer M (1 ≤ M ≤ 250 000) - the number of queries. The next M lines contain three integeres t,  p,  h (0 ≤ t ≤ 2,  - 228 ≤ p, h ≤ 228) - the type of the query, the pH index and the Feng Shui index.

If the type is 0, you must answer Steven what's the minimal cost to transform the land patch defined by the pH and the Fend Shui index to a current permitted one.

If the type is 1 the current land patch becomes permitted and if the type is 2 it becomes forbidden.

One land patch can become permitted multiple times, even if was already permitted, but one query that makes it forbidden overrides it. This applies both ways.

Output

For each of Steven's questions, provide the minimal cost to transform the queried land patch into a land patch that is valid at that current time.

ExampleInput
4
2 3
1 1
0 0
5 7
4
1 5 6
0 5 5
2 1 1
0 1 1
Output
1
2

加入题单

上一题 下一题 算法标签: