Piece Game
Time limit1.5sMemory limit1024 MB
Given an integer array with distinct values and a move limit D, answer whether the first player wins a piece game under optimal play, with point updates to the array.
- Level
Hard8 of 10
- Topics
- Game theory, Segment tree, Array
- Solved
- No attempts yet
Statement
Klimi and Nikol have an integer array with cells numbered from to . The values in the array are all different.
The girls play a game with a single piece that is moved around the array. The piece starts in some cell. One move proceeds as follows:
- The player whose turn it is moves the piece to another cell at distance at most from the current one. If the piece is in cell (), the player may move it to cell () when and . A player must move the piece.
- After moving the piece to cell , the player adds to her score. The score is added after the move.
The moves alternate, and Klimi plays first. The game ends after exactly turns. The girl with the higher total score wins. If the scores are equal, Klimi wins.
The girls want to know the optimal results in several scenarios. You are given the initial array and the value , and you must process queries of two types:
- Update: a single value in the array is changed.
- Question: determine whether Klimi, who plays first, wins from a given initial position under optimal play.
Updates persist across queries, so each question uses all updates made so far.
Constraints
-
index,startIndex -
newValue - The values in are all different at all times, including after updates.