Codeforces Round #548 (Div. 2) A. Even Substrings

You are given a string ?=?1?2??s=s1s2…sn of length ?n, which only contains digits 11, 22, ..., 99.

A substring ?[??]s[l…r] of ?s is a string ????+1??+2??slsl+1sl+2…sr. A substring ?[??]s[l…r] of ?s is called even if the number represented by it is even.

Find the number of even substrings of ?s. Note, that even if some substrings are equal as strings, but have different ?l and ?r, they are counted as different substrings.

Input

The first line contains an integer ?n (1?650001≤n≤65000) — the length of the string ?s.

The second line contains a string ?s of length ?n. The string ?s consists only of digits 11, 22, ..., 99.

Output

Print the number of even substrings of ?s.

Examples
input
Copy
4
1234
output
Copy
6
input
Copy
4
2244
output
Copy
10
Note

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

  • ?[12]s[1…2]
  • ?[22]s[2…2]
  • ?[14]s[1…4]
  • ?[24]s[2…4]
  • ?[34]s[3…4]
  • ?[44]s[4…4]

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

 

 题意:计数以偶数结尾的连续的子串的个数

 思路:遍历一遍,如果当前数字是偶数,则表示可以以它结尾,贡献是它所在的位置大小,加到答案里就好。

 代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define lowbit(x) (x&(-x))
#define eps 0.00000001
#define PI acos(-1)
#define ms(x,y) memset(x, y, sizeof(x))
using namespace std;const int maxn = 65005;
char s[maxn];int main()
{int n;cin >> n;scanf("%s", s+1);ll ans = 0;for(int i=1;i<=n;i++)if((s[i] - '0') % 2 == 0)ans += i;cout << ans << endl;
}

  

转载于:https://www.cnblogs.com/HazelNut/p/10583477.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/248291.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

VI编辑器常用命令

vi —终端中的编辑器 vi 简介 打开和新建文件 三种工作模式 常用命令 分屏命令 01. vi 简介 1.1 学习 vi 的目的 在工作中&#xff0c;要对 服务器 上的文件进行 简单 的修改&#xff0c;可以使用 ssh 远程登录到服务器上&#xff0c;并且使用 vi 进行快速的编辑即可 常见…

kubectl 常用命令

1. 查看镜像定义的内容 docker image inspeck 镜像名:版本 2. 查看可回滚历史 # myapp-deploy 指定哪个 deployment kubectl rollout history deployment myapp-deploy 3. 回滚到上一个版本 # rollout undo 回滚到上一版本的 deployment kubectl rollout undo deployment mya…

javaScript基础讲义第四天(1)

05-javaScript基础 核心知识点 数组操作字符串方式获取系统时间Math相关方法 今日目标 能够完成数组相关案例能后获取系统时间能够操作随机数能够完成小娜案例**[最终的目标]** 数组 思考如果我们希望同时保存多条数据该怎么办&#xff1f;【例如&#xff1a;如何将班上所…

20175213 2018-2019-2 《Java程序设计》第4周学习总结

## 教材学习内容总结 在第四周的学习过程中&#xff0c;我学习了第五章的内容。 第五章内容总结&#xff1a; 1.子类继承的方法只能操作子类继承和隐藏的成员变量。 2.子类和父类在同一包的继承性 子类自然继承了其父类中不是private的成员作为自己的成员。 3.子类和父类不在同…

Machine Schedule为什么UVA过了POJ过不了

UVA1194 POJ1325 POJ要多判一个非零&#xff01;&#xff01;&#xff01; #include<cstdio> #include<vector> #include<cstring> using namespace std; vector<int>e[105]; int vis[105]; int link[105]; int t; int find(int x) {for(int i0;i<e…

课堂笔记

javaScript基础 01.数组 复习数组 数组的意义 程序中可能会遇到一次保存多条数据情况,使用数组解决问题.数组也是一个保存数据的一个容器定义 通过字面量方式定义数组(推荐) var ary [];通过构造函数定义数组(了解) var ary new Array();赋值 通过索引的方式给数组赋值 va…

写一个使两个整数进行交换的方法(不能使用临时变量) 【前端每日一题-27】...

写一个使两个整数进行交换的方法&#xff08;不能使用临时变量&#xff09;这道题是一个比较有意思的题&#xff0c;记录于此。var a10; var b20;...不用临时变量让a和b交换console.log(a); console.log(b);复制代码es6 对象扩展[a,b][b,a];复制代码利用执行顺序aab; ba-b; aa-…

CS 320—Week 8 Homewor

CS 320—Week 8 Homework—Due W 3/27 11:59pmWrite your answers to the problems in the space indicated. Scan your solution and submitto Gradescope as a PDF file. You will receive an email about the Gradescope account.You may do this from your phone using fre…

javascript随堂练习(分支,循环语句)

var flag true;//while语句执行&#xff1a;while(flag){//获取用户输入选择信息号码&#xff1a;&#xff08;字符串中的 \n 为换行的效果&#xff09; var num prompt(你好,我是小娜\n请输入编号或者关键词选择功能,输入Q(q)退出聊天\n1.计算\n2.时间\n3.笑话) // 利用swit…

vue组件间函数调用

vue父子组件间函数调用 <Child ref"myChild"></Child> // 父组件 // 引入子组件 import Child from ./Child export default {// 注册子组件components: {Child},created () {// 调用子组件中的childMethod&#xff0c;并且传递参数data&#xff0c;需要…

Cocoapods pod update执行失败报错CocoaPods was not able to update the `master` repo.2019的解决...

很久没动pod&#xff0c;最近更新发现&#xff1a; CocoaPods报CocoaPods was not able to update the master repo. If this is an unexpected issue and persists you can inspect it running pod repo update --verbose错误。 使用命令pod repo update --verbose依然 不行&a…

javaScrip第五天(1)

06JavaScript基础 核心知识点 函数 2. 函数中的参数 2. 函数中的返回值 今日学习目标 能够完成函数相关案例 2. 能够理解函数中的参数 2. 能够理解函数中的返回值 函数 为什么要学函数&#xff1f; 1.求 1到100之间的数字之和什么是函数&#xff1f; 函数的概念 函数&…

伪静态回发

&#xff08;1&#xff09;自定义一个Actionlessform类&#xff0c;在aspx中不再使用系统提供的form 标记 创建此类并对其进行编译之后&#xff0c;要在 ASP.NET Web 应用程序中使用它&#xff0c;应首先将其添加到 Web 应用程序的 References 文件夹中。然后&#xff0c;要 使…

Supercomputer 解题报告

Supercomputer 设\(f_i\)为前\(i\)个时间内必须的完成的任务个数&#xff0c;那么答案就是\[ \max_{i}\lceil\frac{f_i}{i}\rceil \] 现在要支持区间加和全局\(\max\) 考虑分块&#xff0c;对每个块维护一个\(tag\)表示加标记 块内的\(\max\)则为\[ \max_i \frac{1}{i}\times t…

OCS (错误代码: 0-1-492)

http://hi.baidu.com/windowserver/blog/item/dcd6b851151d062d43a75b72.html 转载于:https://www.cnblogs.com/hubj/archive/2010/06/12/1757279.html

javaScript第五天(2)

javaScript基础 01.知识点-函数【重点】 学习函数的目的 就是为将重复的功能代码包装成一个工具(盒子), 方便程序员重复调用学习函数的路径 定义函数调用函数为了让函数的功能更加强大, 学习函数的 参数函数的返回值 函数的使用 函数的定义及调用 函数的定义 通过 function关…

How to ignore files and directories in subversion?

Step 1 Copy the files and directories to other place. Step 2 Delete the files and directories. Step 3 Commit. Step 4 Paste the files and directories from backup place. Step 5 Commit.转载于:https://www.cnblogs.com/mouseleo/p/10605322.html

arguments使用

只有函数才有argumentsfunction fn(){console.log(arguments);console.log(arguments.length);console.log(arguments[2]);//我们可以按照数组的方式遍历argumentsfor (let i 0; i < arguments.length; i) {console.log(arguments[i]);}}fn(1,2,3);伪数组 并不是真正意义上…

2.0 es6中forEach以及数组操作

前言&#xff1a; 小白的js之路...... 1. 遍历数组/集合 forEach usernameArray []; //遍历 users.forEach((user, index) > {let username user.name;//取出用户名添加到数组usernameArray[index] username; }) 2. 数组过滤filter()和查找find() let arr s.filter( x &…

输出GPLT

L1-023 输出GPLT &#xff08;20 分)给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序&#xff0c;按GPLTGPLT....这样的顺序输出&#xff0c;并忽略其它字符。当然&#xff0c;四种字符&#xff08;不区分大小写&#xff09;的个数不一定是一样多的…