日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2023/12/13 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #548 (Div. 2) A. Even Substrings 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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.

?

?題意:計數(shù)以偶數(shù)結(jié)尾的連續(xù)的子串的個數(shù)

?思路:遍歷一遍,如果當前數(shù)字是偶數(shù),則表示可以以它結(jié)尾,貢獻是它所在的位置大小,加到答案里就好。

?代碼:

#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; }

  

轉(zhuǎn)載于:https://www.cnblogs.com/HazelNut/p/10583477.html

總結(jié)

以上是生活随笔為你收集整理的Codeforces Round #548 (Div. 2) A. Even Substrings的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。