#P9358. [ICPC 2022 Xi'an R] Bridge

    ID: 8622 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>平衡树2022O2优化Link-Cut Tree,LCTICPC

[ICPC 2022 Xi'an R] Bridge

题目描述

There are nn countries numbered from 11 to nn in Erathia. Each country can be regarded as a chain with m+1m+1 nodes numbered from 11 to m+1m+1. Initially, node (a,b)(a, b) is connected with node (a,b+1)(a, b + 1) by a street where node (a,b)(a, b) denotes the bb-th node of the aa-th country. There are no bridges between any two countries at first.

You need to process qq queries of the following two types.

  • 1 a b1\ a\ b (1a<n,1bm1\leq a < n, 1\leq b\leq m). Build a bridge between node (a,b)(a, b) and node (a+1,b)(a + 1, b). It is guranteed that at any time, each node is connected with at most one bridge.
  • 2 a2\ a (1an1\leq a\leq n). A hero will walk through Erathia. This hero starts from (a,1)(a, 1). If the hero is at (x,y)(x, y) and there is a unvisited bridge connected to him, he passes it, or he goes to (x,y+1)(x, y + 1). Once he arrived the (m+1)(m+1)-th node of any conutry, he stops. Please note that 'unvisited bridge' is independently judged for each query.

Your task is to print which country the hero is in at last for the second kind of query. It can be proved that the hero's route is always unique under these constraints.

输入格式

The first line contains three integers nn, mm and qq (1n,m,q1051 \leq n, m, q \leq 10 ^ 5).

Each of the following qq lines represents a query with format described above.

输出格式

For each query of type 22, output a line with an integer representing the answer.

3 4 13
2 2
1 1 3
2 1
2 2
2 3
1 2 4
2 1
2 2
2 3
1 2 1
2 1
2 2
2 3

2
2
1
3
3
1
2
3
2
1

提示

Source: The 2022 ICPC Asia Xi'an Regional Contest Problem A.

Author: MonkeyKing.