Ahoy, Pirates!
Solution sketch
The key thing to come up with is how to store the data and operations.
We can store operation $F$ as 1 (means convert all to 1), $E$ as 0 (means convert all to 0), and $S$ as 2 (means inverse). If no operation is needed, we simply store -1.
The getStatus()
method tells you what operation type you need to convert to when a new operation is requested. For example, if a node originally has an operation tag of $F$ (convert all to 1) and a new tag is $I$ (inverse all pirates), then the combined effect is $E$ (convert all to 0).
For every node, keep the total number of Buccaneer.
Use segment tree with lazy propagation to solve this problem. :) It’s a good one to try!
AC code
|
|