You are building a new game called Dreamrise. The game is played by 2 teams and each match usually lasts around 15 minutes. You are currently building the leaderboard feature. There will be multiple leaderboards both worldwide and regional. In a leaderboard with teams, each team is given a unique id from 1 to . Every team is ranked based on its win rate within a leaderboard. If multiple teams have the same win rate, they are given the same rank. A team is unranked until they play any game.
You have to support 3 types of operations to implement the leaderboard feature.
: Teams with id and played a match. The team with id is the winner.
: Print the current rank of the team with id . If the team is unranked, print -1.
: Print the id of the team having a rank of . If no team is ranked currently, print -1. If multiple teams have the rank , print the team with the smallest ID.
The first line of input contains two integers () and (), denoting number of teams and number of operations respectively. Next lines will have one of the 3 operations described in statement.
Print the desired answer for the operation of type 2 and 3. Do not print anything for operation of type 1.
5 10 1 2 1 1 2 3 1 1 5 1 3 5 2 1 2 4 3 2 3 4 3 3 3 5
2 -1 1 5 -1 -1
Team 2 played with Team 1, Team 3 and won both matches. Both team 1 and team 3 won with Team 5. Team 4 hasn't played any match yet.
Large data set. Use faster I/O.
The win rate is not necessarily an integer.