Editorial for QCC P2 - Online School


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: sjay05

Subtask 1

Brute force suffices.

Time Complexity: O(NQ)

Subtask 2

Notice for each type of query:

1 w: denotes max(maxi=1nyi,xw).

  • If the array y is sorted, the values in the column are ordered as: max(y1,xw)max(y2,xw)max(yn,xw). The maximal value is: max(yn,xw).

2 w: denotes max(mini=1nyi,xw).

  • If the array y is sorted, the values in the column are ordered as: max(y1,xw)max(y2,xw)max(yn,xw). The minimal value is: max(y1,xw).

3 w: denotes max(maxi=1nxi,yw).

  • If the array x is sorted, the values in the row are ordered as: max(x1,yw)max(x2,yw)max(xn,yw). The maximal value is: max(xn,yw).

4 w: denotes max(mini=1nxi,yw).

  • If the array x is sorted, the values in the row are ordered as: max(x1,yw)max(x2,yw)max(xn,yw). The minimal value is: max(x1,yw).

The max and min of arrays x and y can be found in O(N) time and stored before answering any queries.

Time Complexity: O(N+Q)


Comments

There are no comments at the moment.