【杂题】 codeforces 451D Count Good Substrings

来源:互联网 发布:curl json 格式化 编辑:程序博客网 时间:2024/05/16 08:55

一道数学题。。。刚开始看以为是后缀数组。。。然后用后缀数组做啊做啊。。调啊调啊。。。晕晕,后来发现题目中只有a和b。。。晕晕。。就挨个加与它之前相同字符且奇偶和它不同的就行了。。。晕晕。。

#include <iostream>  #include <queue>  #include <stack>  #include <map>  #include <set>  #include <bitset>  #include <cstdio>  #include <algorithm>  #include <cstring>  #include <climits>  #include <cstdlib>#include <cmath>#include <time.h>#define maxn 100005#define eps 1e-10#define mod 1000000009#define INF 99999999  #define lowbit(x) (x&(-x))  //#define lson o<<1, L, mid  //#define rson o<<1 | 1, mid+1, R  typedef long long LL;//typedef int LL;using namespace std;int pre[3][3];char s[maxn];int main(void){scanf("%s", s);int len = strlen(s);LL even = 0, odd = 0;for(int i = 0; i < len; i++) {int tmp = s[i] - 'a';pre[tmp][i%2]++;even += pre[tmp][(i%2)^1];odd += pre[tmp][i%2];}printf("%I64d %I64d\n", even, odd);return 0;}


0 0