[SEERC 2020] Divisible by 3

Luogu
IDLGP10740
Time2000ms
Memory256MB
DifficultyP3
2020ICPCSEERC
定义一个序列 $b$ 的权重为 $\sum_{i=1}^n \sum_{j=1}^{i-1} b_i \times b_j$。 现在你有一个长度为 $n$ 的数组 $a$,求一共存在多少种 $(l,r)$ 使得 $1 \leq l \leq r \leq n$ 且 $[a_l, a_{l+1},\ldots,a_r]$ 的权重能被 $3$ 整除。 ## Input 第一行一个整数 $n\ (1 \leq n \leq 5 \times 10^5)$。 然后 $n$ 个整数 $a_i\ (0 \leq a_i \leq 10^9)$。 ## Output 输出方案总数。 [samples] ## Note 对于第一个样例,存在 $[1,1]$、$[2,2]$、$[3,3]$、$[1,3]$ 共 $4$ 种方案。
Samples
Input #1
3
5 23 2021
Output #1
4
Input #2
5
0 0 1 3 3
Output #2
15
Input #3
10
0 1 2 3 4 5 6 7 8 9
Output #3
20
API Response (JSON)
{
  "problem": {
    "name": "[SEERC 2020] Divisible by 3",
    "description": {
      "content": "定义一个序列 $b$ 的权重为 $\\sum_{i=1}^n \\sum_{j=1}^{i-1} b_i \\times b_j$。 现在你有一个长度为 $n$ 的数组 $a$,求一共存在多少种 $(l,r)$ 使得 $1 \\leq l \\leq r \\leq n$ 且 $[a_l, a_{l+1},\\ldots,a_r]$ 的权重能被 $3$ 整除。",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": {
      "LuoguStyle": "P3"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP10740"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "定义一个序列 $b$ 的权重为 $\\sum_{i=1}^n \\sum_{j=1}^{i-1} b_i \\times b_j$。\n\n现在你有一个长度为 $n$ 的数组 $a$,求一共存在多少种 $(l,r)$ 使得 $1 \\leq l \\leq r \\leq n$ 且 $[a_l, a_{l+1},\\ldots,a_r]$ 的权重能被 $3$ 整除。\n\n## Input\n\n第一行一个整数 $n\\ (...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments