{"raw_statement":[{"iden":"statement","content":"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. \n\nSteven 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.\n\nSteven 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.\n\nThe 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.\n\nThe 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. \n\nIf 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.\n\nIf the type is 1 the current land patch becomes permitted and if the type is 2 it becomes forbidden.\n\nOne 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.\n\nFor 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.\n\n"},{"iden":"input","content":"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."},{"iden":"output","content":"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."}],"translated_statement":null,"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ P \\subseteq \\mathbb{Z}^2 $ be the set of currently permitted land patches, initialized with $ N $ given points $ (p_i, h_i) $.  \nLet $ F \\subseteq \\mathbb{Z}^2 $ be the set of currently forbidden land patches, initialized as $ \\emptyset $.  \n\n**Constraints**  \n1. $ 1 \\le N \\le 250{,}000 $  \n2. $ 1 \\le M \\le 250{,}000 $  \n3. For all $ (p, h) \\in P \\cup F $: $ -228 \\le p, h \\le 228 $  \n4. For each query $ (t, p, h) $:  \n   - If $ t = 0 $: query for minimal cost to transform $ (p, h) $ to some point in $ P $.  \n   - If $ t = 1 $: add $ (p, h) $ to $ P $, remove it from $ F $ if present.  \n   - If $ t = 2 $: add $ (p, h) $ to $ F $, remove it from $ P $ if present.  \n5. $ P \\cap F = \\emptyset $ always holds.  \n\n**Objective**  \nFor each query of type $ t = 0 $ with point $ (p, h) $, compute:  \n$$\n\\min_{(p', h') \\in P} \\left( |p - p'| + |h - h'| \\right)\n$$","simple_statement":"Steven has a farm with land patches. Each patch has a pH and Feng Shui value. He can change either value by 1 for $1.\n\nInitially, there are N permitted patches.  \nThen, M queries come in 3 types:\n\n- Type 0: Find the minimum cost to change the given (p, h) patch to match any currently permitted patch.  \n- Type 1: Make the patch (p, h) permitted.  \n- Type 2: Make the patch (p, h) forbidden (if it was permitted).\n\nCost to change (p1, h1) to (p2, h2) is |p1 - p2| + |h1 - h2|.\n\nFor each type 0 query, output the smallest possible cost.","has_page_source":false}