시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.5 초 1024 MB38151147.826%

문제

The Infrastructure Consortium for Public Compute (ICPC) is a network of computers ran by volunteers from all around the world that share compute resources with one another. Contributors are able to plug and unplug their machines on the network, and also to run compute jobs on the network machines. With the ICPC, important projects that would otherwise have prohibitive infrastructure costs (like running online judges for programming competitions) become viable endeavors.

As great as it sounds on paper, for now, the ICPC is just a dream. To make it work, a key piece of software is missing: the job allocator. This is where you come in: the community is counting on you to make this important (but voluntary, of course) contribution.

The network is extremely dynamic: machines connect and disconnect all the time. The job allocator needs to keep track of the machines that are currently connected and which resources they share. There are several types of resources, such as CPU cores, GPUs, and SSD disks. One machine can share one or more resources, possibly more than one of the same type. Moreover, at any point in time, users can request machines to run compute jobs. For that, they specify a list of resources that a machine needs to run their job, and the job allocator has to determine how many of the currently connected machines have all the required resources to run the job. For example, for a job that needs one CPU core and two GPUs, the allocator would need to count how many machines have at least one CPU core, and two or more GPUs.

Your task is to simply count how many connected machines satisfy each job’s resource requirements, since another volunteer took on the task of implementing the actual assignment of jobs to machines. The whole ICPC community depends on you. Are you able to help?

입력

The first line contains two integers N (1 ≤ N ≤ 105) and K (1 ≤ K ≤ 8), indicating respectively the number of network events that must be processed and the number of types of resources that are available on the ICPC. Events are described in chronological order in the next N lines, one event per line. There are three types of events.

If the event represents that a new machine is being connected to the network, the line contains the uppercase letter “C”, followed by an integer R (1 ≤ R ≤ 8) indicating the number of resources the machine is sharing, followed by R integers T1, T2, . . . , TR (1 ≤ Ti ≤ K for i = 1, 2, . . . , R), describing the type of each of the shared resources. New machines are implicitly assigned unique sequential integer identifiers by the ICPC, starting at 1.

When the event represents that a machine is being disconnected from the network, the line contains the uppercase letter “D”, followed by an integer indicating the identifier of the machine. It is guaranteed that this identifier corresponds to a valid connected machine.

Finally, if the event represents that a user wants to run a job, the line contains the uppercase letter “J”, followed by an integer R (1 ≤ R ≤ 8) indicating the number of resources the job needs, followed by R integers T1, T2, . . . , TR (1 ≤ Ti ≤ K for i = 1, 2, . . . , R), describing the type of each of the required resources. It is guaranteed that the input contains at least one event of this type.

출력

Output a line for each event of type “J”. The line must contain an integer indicating the number of machines that at the moment of the event are connected to the network and provide all the requested resources. Write the results in chronological order, that is, using the same order as the input.

예제 입력 1

3 2
C 3 1 1 2
J 2 1 2
J 2 2 2

예제 출력 1

1
0

예제 입력 2

11 3
C 2 1 2
J 1 3
C 3 1 2 3
J 1 3
J 1 1
D 2
J 1 3
J 2 1 2
J 2 1 1
D 1
J 1 2

예제 출력 2

0
1
2
0
1
0
0

출처

ICPC > Regionals > Latin America > Latin America Regional Contests > Latin America Regional Contests 2020 J번

  • 문제를 만든 사람: Gabriel Poesia