Spreading a Virus in K512
InterviewTime limit2sMemory limit512 MB
Process infect and cure queries on N computers, and print how many computers are uninfected for each count query.
- Level
Easy2 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
K512 is busy preparing for the K512 Cup, which is held tomorrow. K512 has computers in total, numbered from to .
Seunghyeong, who likes pranks, plans to spread a virus to the PCs in K512 and ruin the K512 Cup. Geunsu notices the plan and tries to cure the PCs so that they return to an uninfected state. Initially, every computer is uninfected. Given the numbers of the computers that Seunghyeong infects and that Geunsu cures, find the number of uninfected PCs in K512.
Input
The first line contains the number of computers and the number of queries . Each of the next lines contains one of the following queries.
- : Seunghyeong infects computer . He may infect a computer that is already infected, and nothing changes in that case.
- : Geunsu cures computer , making it uninfected. He may cure a computer that is already uninfected, and nothing changes in that case.
- : Print the current number of uninfected computers in K512.
Output
For each query of type , print the answer on its own line. There is at least one query of type .
Hint
If input and output are slow, reading or printing many lines can cause a time limit error, so the following methods are recommended for each language.
-
C++: If you use
cin/cout, put the following two lines at the start ofmainand print a newline character (\n) instead ofendl. After doing this, you must not use C I/O such asscanf/printf/puts/getchar/putchar.cin.tie(nullptr);sync_with_stdio(false);
-
Python: Use the following instead of
input.sys.stdin.readline.rstrip()
-
Java, Kotlin: Use
BufferedReaderandBufferedWriterinstead ofScannerandSystem.out.println. CallBufferedWriter.flushonly once, before the program exits.