| Game of Coders 5.0 | Finals Round |
|---|
| Finished |
Sherbiny and Samer Samora are optimizing the core database engine for the Sunny's navigation logs. They need to implement a buffer pool of capacity $$$C$$$ to keep frequently accessed data pages in fast memory.
The pool can hold up to $$$C$$$ distinct pages, each identified by a positive integer. When a page is read or written, it is brought into the pool and becomes the most recently accessed page. If the pool is already at full capacity $$$C$$$ and a new page must be brought in, the Least Recently Used (LRU) page is evicted to make room.
A write operation modifies a page, marking it as dirty. If a dirty page is evicted from the pool, it is completely removed and is no longer considered dirty.
You must process $$$Q$$$ queries of the following four types:
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^{4}$$$) — the number of test cases.
The first line of each test case contains two integers $$$C$$$ and $$$Q$$$ ($$$1 \le C \le 10^{5}$$$, $$$1 \le Q \le 2 \times 10^{5}$$$) — the capacity of the buffer pool and the number of queries.
The next $$$Q$$$ lines describe the queries in the format given above. All page IDs satisfy $$$1 \le x \le 10^{9}$$$.
It is guaranteed that the sum of $$$Q$$$ over all test cases does not exceed $$$2 \times 10^{5}$$$.
For each test case, output the answers for the Flush and Status queries in the order they appear:
12 81 102 204 104 202 304 1034 20
1 01 10 021 0
In the first test case, the buffer pool has capacity $$$C = 2$$$.
After reading page $$$10$$$, the pool contains page $$$10$$$ (clean). After writing page $$$20$$$, the pool contains pages $$$10$$$ and $$$20$$$, with page $$$20$$$ marked as dirty.
The first status query for page $$$10$$$ reports 1 0 (in pool, clean). The second status query for page $$$20$$$ reports 1 1 (in pool, dirty).
Writing page $$$30$$$ brings in a new page while the pool is full. Page $$$10$$$ is the least recently used, so it is evicted. The pool now contains pages $$$20$$$ and $$$30$$$, both dirty.
The status query for page $$$10$$$ now reports 0 0 because it was evicted.
The flush query finds $$$2$$$ dirty pages ($$$20$$$ and $$$30$$$), outputs 2, and marks them both as clean.
The final status query for page $$$20$$$ reports 1 0 because it is still in the pool, but was cleaned by the flush.
| Name |
|---|


