#K9121. Team Skill Sum Game

    ID: 37925 Type: Default 1000ms 256MiB

Team Skill Sum Game

Team Skill Sum Game

You are given N players, numbered from 1 to N. Each player has a unique skill rating and is initially assigned to a team. The game organizer conducts Q operations. There are two types of operations:

  • 1 p t: Move player p to team t.
  • 2 t: Query the maximum sum of the skill ratings of any two distinct players in team t. If the team has fewer than two players, the answer is 0.

Formally, let \(S_i\) be the skill of the \(i\)th player and \(T_i\) be the team of the \(i\)th player. After processing each query of the type 2 t, you should output the value:

\[ \max_{\substack{i,j \;:\; i \neq j \\ T_i = T_j = t}} (S_i + S_j), \]

or 0 if there are less than two players in team t.

inputFormat

The input is read from stdin and has the following format:

N Q
s1 t1
s2 t2
... 
sN tN
query1
query2
...
queryQ

where:

  • \(N\) is the number of players.
  • \(Q\) is the number of queries.
  • Each player is described by two integers: the skill rating \(s_i\) and the initial team \(t_i\).
  • Each query is either in the format 1 p t (move player p to team t) or 2 t (query for team t).

outputFormat

For each query of type 2 t, output the maximum sum of the skills of two different players in team t on a separate line. If there are fewer than two players in team t, output 0.

## sample
5 6
10 1
20 1
30 2
40 3
50 3
1 1 3
2 1
2 2
1 4 1
2 1
2 3
0

0 60 60

</p>