CF1139A.Even Substrings

入门

通过率:0%

时间限制:0.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string s=s1s2…sns=s_1s_2\dots s_n of length nn, which only contains digits 11, 22, ..., 99.

A substring s[l…r]s[l \dots r] of ss is a string slsl+1sl+2…srs_l s_{l + 1} s_{l + 2} \ldots s_r. A substring s[l…r]s[l \dots r] of ss is called even if the number represented by it is even.

Find the number of even substrings of ss. Note, that even if some substrings are equal as strings, but have different ll and rr, they are counted as different substrings.

给你一个长度为 nn 的字符串 s=s1s2…sns=s_1s_2\dots s_n,其中仅包含数字 1,2,…,91, 2, \dots, 9。

字符串 ss 的一个子串 s[l…r]s[l \dots r] 定义为字符串 slsl+1sl+2…srs_l s_{l + 1} s_{l + 2} \ldots s_r。若该子串所表示的数为偶数,则称其为偶子串。

请你求出 ss 中偶子串的个数。注意:即使两个子串作为字符串相等,但只要其起始位置 ll 或结束位置 rr 不同,就视为不同的子串。

输入格式

The first line contains an integer nn (1≤n≤650001 \le n \le 65000) — the length of the string ss.

The second line contains a string ss of length nn. The string ss consists only of digits 11, 22, ..., 99.

第一行包含一个整数 nn(1≤n≤650001 \le n \le 65000)—— 字符串 ss 的长度。

第二行包含一个长度为 nn 的字符串 ss。字符串 ss 仅由数字 11、22、…、99 组成。

输出格式

Print the number of even substrings of ss.

输出字符串 ss 中偶数子串的数量。

输入输出样例

  • 输入#1

    4
    1234

    输出#1

    6
  • 输入#2

    4
    2244

    输出#2

    10

说明/提示

In the first example, the [l,r][l, r] pairs corresponding to even substrings are:

  • s[1…2]s[1 \dots 2]
  • s[2…2]s[2 \dots 2]
  • s[1…4]s[1 \dots 4]
  • s[2…4]s[2 \dots 4]
  • s[3…4]s[3 \dots 4]
  • s[4…4]s[4 \dots 4]

In the second example, all 1010 substrings of ss are even substrings. Note, that while substrings s[1…1]s[1 \dots 1] and s[2…2]s[2 \dots 2] both define the substring "2", they are still counted as different substrings.

在第一个例子中,对应偶子串的 [l,r][l, r] 对为:

  • s[1…2]s[1 \dots 2]
  • s[2…2]s[2 \dots 2]
  • s[1…4]s[1 \dots 4]
  • s[2…4]s[2 \dots 4]
  • s[3…4]s[3 \dots 4]
  • s[4…4]s[4 \dots 4]

在第二个例子中,ss 的全部 1010 个子串均为偶子串。注意:尽管子串 s[1…1]s[1 \dots 1] 和 s[2…2]s[2 \dots 2] 均表示子串 "2",它们仍被计为不同的子串。

输入解题思路,AI测评打分。不知道怎么写?

首页