Under construction

Still being built. Things may change

Piece Game

Time limit1.5sMemory limit1024 MB

Summary
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 AA with NN cells numbered from 00 to N−1N - 1. 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:

  1. The player whose turn it is moves the piece to another cell at distance at most DD from the current one. If the piece is in cell xx (0≤x<N0 \le x < N), the player may move it to cell yy (0≤y<N0 \le y < N) when ∣y−x∣≤D|y - x| \le D and x≠yx \ne y. A player must move the piece.
  2. After moving the piece to cell yy, the player adds AyA_y to her score. The score is added after the move.

The moves alternate, and Klimi plays first. The game ends after exactly 1010010^{100} 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 AA and the value DD, and you must process QQ 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

  • 1≤N,Q≤2⋅1051 \le N, Q \le 2 \cdot 10^5
  • 1≤D≤251 \le D \le 25
  • 1≤Ai≤1091 \le A_i \le 10^9
  • 0≤0 \le index, startIndex <N< N
  • 1≤1 \le newValue ≤109\le 10^9
  • The values in AA are all different at all times, including after updates.

Examples1

  1. Example 1

    Input
    2 1 1
    1 2
    2 0
    
    Expected output
    Klimi