#P7603. [THUPC 2021] 鬼街

[THUPC 2021] 鬼街

Description

That street is known as the “Ghost Street”. Ten years ago, it was one of the busiest areas in City A, but now no living person lives there.

Along the street, there are nn houses scattered here and there. Each house has a unique number between 11 and nn, painted in hellish black paint on broken tiles and crumbling bricks, faintly visible in the yellow dust.

It is said that the ghosts on this street are different from ghosts elsewhere. They like studying number theory and choose where to live based on properties of numbers, which is why they assigned a number to every house.

The newly appointed mayor of City A does not believe in such supernatural rumors. To find out the truth, he decides to install paranormal event monitors on this street.

There are mm events happening in order, as follows.

  • Paranormal event: In the houses whose numbers are all prime factors of xx, each such house experiences yy haunting occurrences. For mysterious reasons, yy may be 00.
  • Monitoring event: A monitor is installed. It monitors the houses whose numbers are all prime factors of xx. When the accumulated total number of haunting occurrences reaches the threshold yy, this monitor will trigger an alarm (if y=0y = 0, then no matter which houses are being monitored, the next paranormal event will immediately trigger this monitor’s alarm). Haunting counts from different houses are tracked separately, and different monitors do not affect each other. All monitors are numbered consecutively starting from 11.

Please report all alarms to the mayor, that is, after each paranormal event, output which monitors are triggered.

Input Format

The first line contains two positive integers nn and mm, with 1<n,m1051 < n, m \le {10}^5.

The next mm lines each contain three non-negative integers opop, xx, and yy'. Here op{0,1}op \in \{ 0, 1 \}. If opop is 00, it is a paranormal event; if opop is 11, it is a monitoring event. It is guaranteed that 1<xn1 < x \le n and 0y<2320 \le y' < 2^{32}. For mysterious reasons, you cannot directly obtain the real yy. Let kk' be the number of monitors triggered by the previous paranormal event (if no paranormal event has happened yet, then k=0k' = 0). The real yy is yky' \oplus k'. The meanings of xx and yy in each event are as described above.

Output Format

For each paranormal event, output one line in order. The line starts with a non-negative integer kk, representing the number of alarms triggered by this paranormal event, followed by kk integers in increasing order, representing the indices of the monitors that are triggered.

20 9
1 10 2
0 5 0
0 6 1
0 7 1
0 15 1
1 12 3
0 8 0
1 5 0
0 8 2

0
0
0
1 1
0
2 2 3

Hint

【Sample Explanation】

In this sample, the following events happen in order:

  • Monitor 11 is installed. It monitors houses numbered 22 and 55, with an alarm threshold of 22.
  • A paranormal event happens. House 55 seems to be haunted, but the number of occurrences is 00, so no alarms are triggered.
  • A paranormal event happens. Houses 22 and 33 each have 11 haunting occurrence. The accumulated count on monitor 11 reaches 11, but it has not triggered an alarm yet.
  • A paranormal event happens. House 77 has 11 haunting occurrence, and no alarms are triggered.
  • A paranormal event happens. Houses 33 and 55 each have 11 haunting occurrence. The accumulated count on monitor 11 reaches the threshold 22, so it triggers an alarm.
  • Monitor 22 is installed. It monitors houses numbered 22 and 33, with an alarm threshold of 22.
  • A paranormal event happens. House 22 has 11 haunting occurrence. The accumulated count on monitor 22 reaches 11, but it has not triggered an alarm yet.
  • Monitor 33 is installed, but its threshold is 00, so the next paranormal event will definitely trigger its alarm.
  • A paranormal event happens. House 22 has 22 haunting occurrences. The accumulated count on monitor 22 reaches 33, exceeding its alarm threshold 22, so it triggers an alarm. At the same time, monitor 33 is also triggered.

【Source】

From the 2021 Tsinghua University Student Programming Contest and Collegiate Invitational (THUPC2021).

Resources such as editorials can be found at https://github.com/yylidiw/thupc_0/tree/master.

Translated by ChatGPT 5