[CCC 2015 S1] Zero That Out

Luogu
IDLGP9810
Time1000ms
Memory256MB
DifficultyP2
2015CCC(加拿大)
给定 $k$ 个整数 $a_1,a_2 \dots ,a_k$,维护一个序列,按顺序进行以下操作: - 当 $a_{i} = 0$ 时,将序列中最后加入的数删除。 - 否则,将 $a_{i}$ 加入序列。 例如:当 $a = \{1,3,5,4,0,0,7,0,0,6\}$ 时,操作如下。 |$a_{i}$|序列| |:--:|:--:| |$1$|$\{1\}$| |$3$|$\{1,3\}$| |$5$|$\{1,3,5\}$| |$4$|$\{1,3,5,4\}$| |$0$|$\{1,3,5\}$| |$0$|$\{1,3\}$| |$7$|$\{1,3,7\}$| |$0$|$\{1,3\}$| |$0$|$\{1\}$| |$6$|$\{1,6\}$| 你需要计算最终序列中所有数的和。 ## Input 第一行一个整数 $k$。 接下来 $k$ 行,每行一个整数 $a_i$。 ## Output 输出一行一个整数,表示最终序列中所有数的和。 [samples] ## Note **【数据范围】:** $1 \le k \le 10^5$,$0 \le a_i \le 100$。 保证在 $a_i = 0$ 时序列不为空。
Samples
Input #1
4
3
0
4
0
Output #1
0
Input #2
10
1
3
5
4
0
0
7
0
0
6
Output #2
7
API Response (JSON)
{
  "problem": {
    "name": "[CCC 2015 S1] Zero That Out",
    "description": {
      "content": "给定 $k$ 个整数 $a_1,a_2 \\dots ,a_k$,维护一个序列,按顺序进行以下操作: - 当 $a_{i} = 0$ 时,将序列中最后加入的数删除。 - 否则,将 $a_{i}$ 加入序列。 例如:当 $a = \\{1,3,5,4,0,0,7,0,0,6\\}$ 时,操作如下。 |$a_{i}$|序列| |:--:|:--:| |$1$|$\\{1\\}$| |$3$|$\\{1,3\\",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": {
      "LuoguStyle": "P2"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP9810"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "给定 $k$ 个整数 $a_1,a_2 \\dots ,a_k$,维护一个序列,按顺序进行以下操作:\n\n- 当 $a_{i} = 0$ 时,将序列中最后加入的数删除。\n- 否则,将 $a_{i}$ 加入序列。\n\n例如:当 $a = \\{1,3,5,4,0,0,7,0,0,6\\}$ 时,操作如下。\n\n|$a_{i}$|序列|\n|:--:|:--:|\n|$1$|$\\{1\\}$|\n|$3$|$\\{1,3\\...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments