D. Ghost-or-Treat

Codeforces
IDCF10278D
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
King Boo has $N$ ghosts standing in a line. This year, they decide that they want to go ghosting and treating. While trick-or-treating is relatively simple for humans, for ghosts, instead they need to scare people and steal their candy when they're terrified. But, being ghosts, they're kind of lazy, and so Boo has decided a system where only one ghost will go out and do this task this year so everyone can have some candy. Every single ghost has been a ghost for a certain number of whole number years. Boo has decided to repeatedly pick out two ghosts with different "ages" that are adjacent to each other in the line, and if one of them has been a ghost longer than the other, the younger ghost will step out of line and is no long in the running to be a ghost-or-treater. However, matches are tiring to the participants involved, so the ghost that stays in line will effectively age a year. This process repeats until all Boo can no longer select two ghosts, and Boo will declare the remaining ghost(s) the "winner(s)" to go ghost-or-treating. Given the ages of each of the ghosts in order, is there a way that Boo can set up the matches such that only one ghost will have to go ghost-or-treating (in other words, only one ghost will be remaining in line)? The first line will contain $N$ $(1 <= N <= 10^4)$, the number of ghosts. The next $N$ lines will each contain the age $X$ $(1 <= X <= 10^9)$ of a ghost in years. Output _YES_ if it is possible to send out exactly one ghost, and _NO_ if not. In the first sample case, the matchups can be the following: 1st ghost v.s. 2nd ghost, 1st ghost stays in line and is now 6 years old 1st ghost v.s. 3rd ghost, 1st ghost stays in line and is now 7 years old 4th ghost v.s. 5th ghost, 5th ghost stays in line and is now 6 years old 1st ghost v.s. 5th ghost, 1st ghost stays in line and no one else is left Note that the 1st ghost and 3rd ghost are adjacent after the 2nd ghost steps out of line when the first matchup completes. ## Input The first line will contain $N$ $(1 <= N <= 10^4)$, the number of ghosts.The next $N$ lines will each contain the age $X$ $(1 <= X <= 10^9)$ of a ghost in years. ## Output Output _YES_ if it is possible to send out exactly one ghost, and _NO_ if not. [samples] ## Note In the first sample case, the matchups can be the following:1st ghost v.s. 2nd ghost, 1st ghost stays in line and is now 6 years old1st ghost v.s. 3rd ghost, 1st ghost stays in line and is now 7 years old4th ghost v.s. 5th ghost, 5th ghost stays in line and is now 6 years old1st ghost v.s. 5th ghost, 1st ghost stays in line and no one else is leftNote that the 1st ghost and 3rd ghost are adjacent after the 2nd ghost steps out of line when the first matchup completes.
**Definitions** Let $ n, q \in \mathbb{Z}^+ $ denote the number of grass blades and number of operations, respectively. Let $ A = (a_1, a_2, \dots, a_n) \in \mathbb{Z}^n $ be the initial height vector of the blades, with $ 1 \le a_i \le 10^6 $. Let $ S = \sum_{i=1}^n a_i $ be the total height of all blades. **Operations** For each of the $ q $ operations: 1. **Cutting**: Given $ l, r, h $, update: $$ a_i \leftarrow \min(a_i, h) \quad \forall i \in [l, r] $$ 2. **Transplanting**: Given $ l, r $, perform a cyclic shift: Move the segment $ A[l:r] $ to the end, i.e., $$ A \leftarrow (A[1:l-1] + A[r+1:n] + A[l:r]) $$ 3. **Fertilizing**: Given $ l, r, x $, update: $$ a_i \leftarrow a_i + x \quad \forall i \in [l, r] $$ **Objective** After each operation, output the updated total height: $$ S = \sum_{i=1}^n a_i $$
API Response (JSON)
{
  "problem": {
    "name": "D. Ghost-or-Treat",
    "description": {
      "content": "King Boo has $N$ ghosts standing in a line. This year, they decide that they want to go ghosting and treating. While trick-or-treating is relatively simple for humans, for ghosts, instead they need to",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10278D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "King Boo has $N$ ghosts standing in a line. This year, they decide that they want to go ghosting and treating. While trick-or-treating is relatively simple for humans, for ghosts, instead they need to...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, q \\in \\mathbb{Z}^+ $ denote the number of grass blades and number of operations, respectively.  \nLet $ A = (a_1, a_2, \\dots, a_n) \\in \\mathbb{Z}^n $ be the initial height ve...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments