Editorial for BSSPC '21 S2 - Hacker Soup


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: azeng

Subtask 1

The grid size and number of rotation operations are small, so we simply simulate all the rotation operations as preprocessing. Then, each query can be answered in \mathcal O(1) time.

Time Complexity: \mathcal O(N^2K + Q)

Subtask 2

For each query, we process the rotation operations in reverse. If the queried cell would land in the square of a rotation operation, we "undo" the operation by applying its inverse to the queried cell (rotating 90 degrees counterclockwise). In the end, this leaves us with the location of the queried cell in the original matrix (before any rotation operations), which we know the value of.

Time Complexity: \mathcal O(KQ)


Comments

There are no comments at the moment.