Editorial for Another Random Contest 1 P4 - Bracket Query
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Observations
If two insertions are allowed, one can insert a series of left brackets before
Let's denote all (
as )
as
Subtask 1
Simply enumerate through all positions to check if at any position the prefix sum turns negative or postfix sum turns positive. Output NO
if both occur, and YES
otherwise.
Time Complexity:
Subtask 2
Use any data structure that can answer range minimum query (RMQ), such as a segment tree or sparse table, to find the minimum prefix sum and maximum postfix sum in the interval
Time Complexity:
Comments