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.pswp.cn/news/248291.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/248291.shtml
英文地址,請注明出處:http://en.pswp.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;的個數不一定是一樣多的…