Aju Survival
Time limit1sMemory limit512 MB
Process a log of moves, farms, crafts, and attacks across 53 regions, flag the cheating entries, and list the players to block.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation, Hash map, Array
- Solved
- No attempts yet
Problem
It is 2021, and an online game called "Aju Survival" is hugely popular in South Korea. It is a battle royale game set on Aju Island in the middle of the sea, where players roam the island's many regions, acquire and craft items, and fight other players.
Sangmin is a server developer for Aju Survival. As the game's popularity grew, so did the number of players cheating. Fed up, Sangmin decided to analyze the game logs and find every instance of cheating.

Aju Survival has a total of 53 regions, numbered 1 through 53, and the game starts with every player gathered in region 1 (the main gate).
Players can take four kinds of actions: move, farm, craft, and attack.
- Move: The player moves from their current region to a different region. In other words, they do not move to the region they are already in.
- Farm: The player acquires one material item, and can only acquire the item available in their current region. That is, in region x they acquire material item x. Items are plentiful, so there is never a shortage, and a player may acquire the same item multiple times.
- Craft: The player uses one each of two different kinds of material items they hold to make equipment.
- Attack: The player attacks one other player. They can only attack a player in the same region.
Sangmin considers the following three cases to be cheating.
- The player acquires a material item that cannot be obtained in their current region.
- The player crafts using a material item they do not hold.
- The player attacks an opponent in a different region.
Sangmin: I will log every action that looks like cheating. But I cannot tolerate lying about your location when you attack. I will block players who do that!
The game log is given as follows.
1 11 M 13
2 13 M 15
3 11 F 13
4 11 M 3
5 11 F 3
6 11 C 3 13
7 13 A 11
8 13 F 15
9 13 F 16
10 13 C 15 16
...
Each log entry is recorded in the format "[number] [player number] [action code] [action argument]".
- Number: The line number of the log. It runs from 1 to T in order.
- Player number: The unique number of each player. It is between 1 and N.
- Action code: The action the player took. Move is M (Move), farm is F (Farming), craft is C (Crafting), and attack is A (Attack).
- Action argument: Information about the action the player took. For a move it is the number of the region moved to, for a farm it is the number of the material item acquired, for a craft it is the numbers of the two material items used, and for an attack it is the number of the player attacked.
A material item acquired through cheating still counts as acquired, and when crafting, only the material items the player holds are used.
In the log above, player 11 moves to region 13 (1), acquires material item 13 (3), then moves to region 3 (4), acquires material item 3 (5), and crafts material items 3 and 13 (6). All of these actions are legitimate.
Player 13 moves to region 15 (2), then attacks player 11, who is in region 3 (7). Attacking a player in a different region is cheating, so log entry 7 is recorded, and because it is an attack cheat, player 13 must be blocked. Next, player 13 acquires material item 15 (8), acquires material item 16 (9), and crafts material items 15 and 16 (10). Acquiring material item 16 in region 15 is cheating, so log entry 9 is recorded. However, since acquiring material item 16 still counts, log entry 10 is not cheating.
Analyze the game log for Sangmin and report the recorded cheating and the players to block.
Input
The first line gives the number of game log lines T and the number of players N. (1 ≤ T ≤ 200,000, 1 ≤ N ≤ 100,000)
From the second line, T lines of game log are given. Each line contains the number, player number, action code, and action argument, separated by a single space.
Output
On the first line, print the number of log entries recorded as cheating. If there are none, print "0".
If there are log entries recorded as cheating, on the next line print the numbers of the recorded log entries in ascending order, separated by single spaces. If there are none, do not print that line.
On the next line, print the number of players to block. If there are none, print "0".
If there are players to block, on the next line print the numbers of the players to block in ascending order, separated by single spaces. Even if a player cheats multiple times, print them only once. If there are no players to block, do not print that line.