For $n$ lists $L_i$ $(i = 0, 1, ..., n-1)$, perform a sequence of the following…
- User
For lists , perform a sequence of the following operations.
Assistant
pythonimport sys def main(): n, q = map(int, sys.stdin.readline().split()) lists = [[] for _ in range(n)] # Each list is a list of chunks (each chunk is a list of elements) for _ in range(q): parts = sys.stdin.readline().split() if not parts: continue # Handle possible empty lines, though unlikely in competition inputs if parts[0] == '0': t = int(parts[1]) x = int(parts[2]) if not lists[t]: lists[t].append([x]) else: lists[t][-1].append(x) elif parts[0] == '1': t = int(parts[1]) elements = [] for chunk in lists[t]: elements.extend(chunk) print(' '.join(map(str, elements))) elif parts[0] == '2': s = int(parts[1]) t = int(parts[2]) lists[t].extend(lists[s]) lists[s].clear() if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.