G. Card Game

Codeforces
IDCF10226G
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Zeyad and Ehab are playing a simple card game, each player initially has a deck of $n$ cards numbered from $1$ to $n$, the game lasts $n$ turns and in each turn both players privately choose one card and then both players reveal the chosen cards, the player that chose the card with the higher number earns points equal to that number, for example if Ehab chooses $4$ and Zeyad chooses $6$ Zeyad earns $6$ points, if the numbers chosen are equal no one earns any point, the cards chosen do not return to the deck, they are discarded instead. Ehab doesn't care about winning or losing, he cares about mathematical values of the game, specifically he wants to know the expected number of points he'll earn considering all possible outcomes, can you help him? The first and only line of input contains a single integer $n (1 <= n <= 10^6)$. Print a real number, the expected number of points Ehab will earn in the game. The answer is considered correct if the absolute or relative error is not greater than $10^(-6)$. ## Input The first and only line of input contains a single integer $n (1 <= n <= 10^6)$. ## Output Print a real number, the expected number of points Ehab will earn in the game. The answer is considered correct if the absolute or relative error is not greater than $10^(-6)$. [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of rooms. Let $ P = \{(a_i, b_i) \mid i \in \{1, \dots, n\}\} $ be the set of patient profiles, where $ a_i \in \mathbb{Z}^+ $ is the food demand and $ b_i \in \mathbb{Z}^+ $ is the maximum safe food visibility for patient in room $ i $. Let $ D \subseteq \{1, \dots, n\} $ be the set of rooms with dead patients (initially $ D = \emptyset $). **Constraints** 1. $ 1 \leq n \leq 10^5 $ 2. $ 1 \leq a_i \leq 10^9 $, $ 1 \leq b_i \leq 10^{18} $ for all $ i \in \{1, \dots, n\} $ 3. $ 1 \leq q \leq 10^5 $ **Objective** Process $ q $ queries: 1. **Query type 1 ($ 1 \ x $)**: Given food supply $ x \in \mathbb{Z}^+ $, simulate robot traversal: - Initialize cumulative food used $ s = 0 $. - For $ i = 1 $ to $ n $: - If $ i \in D $, skip. - Else if $ a_i > x - s $, stop traversal. - Else if $ s + a_i > b_i $, mark $ i \in D $ (patient dies). - Else, set $ s \leftarrow s + a_i $. - Let $ d = |D| $ (number of dead patients after traversal). - Let $ u = $ number of rooms $ i \notin D $ such that $ a_i > x - s $ (patients who didn’t receive food). - Output $ (d, u) $. 2. **Query type 2 ($ 2 \ a \ b \ c $)**: Replace patient in room $ c $ with new patient $ (a, b) $: - If $ c \in D $, remove $ c $ from $ D $. - Set $ (a_c, b_c) \leftarrow (a, b) $.
API Response (JSON)
{
  "problem": {
    "name": "G. Card Game",
    "description": {
      "content": "Zeyad and Ehab are playing a simple card game, each player initially has a deck of $n$ cards numbered from $1$ to $n$, the game lasts $n$ turns and in each turn both players privately choose one card ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10226G"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Zeyad and Ehab are playing a simple card game, each player initially has a deck of $n$ cards numbered from $1$ to $n$, the game lasts $n$ turns and in each turn both players privately choose one card ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of rooms.  \nLet $ P = \\{(a_i, b_i) \\mid i \\in \\{1, \\dots, n\\}\\} $ be the set of patient profiles, where $ a_i \\in \\mathbb{Z}^+ $ is the food ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments