Insert XOR

AtCoder
IDarc203_d
Time2000ms
Memory256MB
Difficulty
There is an integer sequence $A=(A_1,A_2,\dots,A_N)$ of length $N$ consisting of $0$ and $1$. You are given $Q$ queries. The $q$\-th query is as follows: * An integer $i_q$ between $1$ and $N$ is given. Change $A_{i_q}$ to $1$ if it is $0$, and to $0$ if it is $1$. After processing each query, find the answer to the following problem: > Consider sequences $B=(B_1,B_2,\dots,B_{|B|})$ consisting of $0$ and $1$ that satisfy the following condition: > > * By performing the following operation any number of times on $B$, it can be made to match sequence $A$: > * Choose an integer $i$ between $1$ and $|B|-1$, inclusive. > * Insert $B_i\oplus B_{i+1}$ between $B_i$ and $B_{i+1}$. > > It can be proved that there always exists a $B$ that satisfies the condition. Find the minimum possible value of $|B|$. ## Constraints * $3 \leq N \leq 2 \times 10^5$ * $0 \leq A_i \leq 1$ * $1 \leq Q \leq 5 \times 10^5$ * $1 \leq i_q \leq N$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $\dots$ $A_N$ $Q$ $i_1$ $i_2$ $\vdots$ $i_Q$ [samples]
Samples
Input #1
3
0 0 0
2
1
2
Output #1
3
2

When $A=(1,0,0)$, $|B|$ is minimized by $B=(1,0,0)$. When $A=(1,1,0)$, $|B|$ is minimized by $B=(1,0)$.
Input #2
8
0 1 0 0 1 1 1 0
3
1
4
1
Output #2
5
2
3
API Response (JSON)
{
  "problem": {
    "name": "Insert XOR",
    "description": {
      "content": "There is an integer sequence $A=(A_1,A_2,\\dots,A_N)$ of length $N$ consisting of $0$ and $1$. You are given $Q$ queries. The $q$\\-th query is as follows: *   An integer $i_q$ between $1$ and $N$ is g",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc203_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is an integer sequence $A=(A_1,A_2,\\dots,A_N)$ of length $N$ consisting of $0$ and $1$. You are given $Q$ queries. The $q$\\-th query is as follows:\n\n*   An integer $i_q$ between $1$ and $N$ is g...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments