In Queries
Time limit1sMemory limit128 MB
Maintain a 5-column table with seeded initial rows and process insert, remove, max, min, and range-count queries over the columns.
- Level
Easy3 of 10
- Topics
- Array, Implementation, Simulation, Brute force
- Solved
- No attempts yet
Problem
A student computing club needs a software module that answers queries over tabular data, and they have asked for your help. All values are integers, stored in a table with exactly 5 columns.
For development, the initial table is generated by the following function:
f(r, c) = (a · f(r-1, c) + b · f(r, c-1) + x) mod m
f(r, c) = 0 for all r = 0 or c = 0
Here f(r, c) is the value in row r and column c, for r = 1 … n and c = 1 … 5. The values a, b, x, m, and n are seeds given in the input.
Your module must handle the following queries:
A remove deletes the given row but does not shift the rows below it: the row stays in place and only its data is cleared. If the target row is already empty or out of range, the command does nothing. An insert always appends a new last row, even when earlier rows are empty (previously deleted).
You may assume that no output query (max, min, or range) is ever issued while the table is empty.
Input
The first line contains an integer T, the number of test cases.
Each test case begins with five non-negative integers a, b, x, m () and n () — the seeds used to generate the initial table. The next line contains a single integer q (), the number of queries. Each of the following q lines contains one query in one of the formats described above.
Output
For each test case, first print Case #X: on its own line, where X is the test case number (starting from 1). Then print the result of each output query (max, min, range) on its own line, in the order the queries appear.