D. Count Good Substrings

题目连接:

http://codeforces.com/contest/451/problem/D

Description

We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba".

Given a string, you have to find two values:

the number of good substrings of even length;
the number of good substrings of odd length.

Input

The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105).

Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.

Output

Print two space-separated integers: the number of good substrings of even length and the number of good substrings of odd length.

Sample Input

bb

Sample Output

1 2

Hint

题意

他定义了一个叫做good串的东西,就是重叠的字符就算作一个,然后如果重叠算一个,且最后是回文串的话,那么他就是好的。

现在给你一个串,问你他的奇数长度good,和偶数长度good各有多少个。

题解:

由于只含有ab,所以这种回文串一定是ababababa这种的,那么只要两端相同就好了。

然后我们统计一下就行。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
char s[maxn];
long long cnt[3][3];
int main()
{
scanf("%s",s);
int len=strlen(s);
long long odd=0,even=0;
for(int i=0;i<len;i++)
{
cnt[s[i]-'a'][i%2]++;
even+=cnt[s[i]-'a'][1-i%2];
odd+=cnt[s[i]-'a'][i%2];
}
printf("%lld %lld\n",even,odd);
}

Codeforces Round #258 (Div. 2) D. Count Good Substrings 水题的更多相关文章

  1. Codeforces Round #258 (Div. 2) D. Count Good Substrings —— 组合数学

    题目链接:http://codeforces.com/problemset/problem/451/D D. Count Good Substrings time limit per test 2 s ...

  2. Codeforces Round #258 (Div. 2) A. Game With Sticks 水题

    A. Game With Sticks 题目连接: http://codeforces.com/contest/451/problem/A Description After winning gold ...

  3. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  4. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  5. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  6. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

  7. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

  8. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  9. Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题

    A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...

随机推荐

  1. Java 在匿名内部函数中为外部函数变量赋值的解决方案

    Java匿名内部函数本人不怎么主动使用,但是经常会调用一些API,其中会调用一些接口,而这些接口是需要使用匿名内部类来实现的,于是就遇到了一些问题. 就比如okHttp3 的接口调用 OkHttpCl ...

  2. Java面试题系列(一)描述一下JVM加载class文件的原理机制

    JVM系列第4讲:从源代码到机器码,发生了什么? https://www.cnblogs.com/chanshuyi/p/jvm_serial_04_from_source_code_to_machi ...

  3. 各种奇妙的hack

    Android Selector Hacks WebKit .selector:not(*:root) {} Chrome * Safari * Opera ≥ 14 Android * # Java ...

  4. TED_Topic9:How we're priming some kids for college — and others for prison

    Alice Goffman In the United States, two institutions guide teenagers on the journey to adulthood: co ...

  5. Windows bat 学习(初级)

    http://steve-jansen.github.io/guides/windows-batch-scripting/part-1-getting-started.html 注释:REM 或 :: ...

  6. 20155314 2016-2017-2 《Java程序设计》第8周学习总结

    20155314 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 了解NIO 会使用Channel.Buffer与NIO2 会使用日志API.国际化 会使用正 ...

  7. python中的__call__

    如果python中的一个类定义了 __call__ 方法,那么这个类它的实例就可以作为函数调用,也就是实现了 () 运算符,即可调用对象协议 下面是一个简单的例子: class TmpTest: de ...

  8. 第14月第1天 uialterview 键盘 uibutton圆角

    1. 在IOS 8之后 当UIAlertView 和keyboard 同时出现时,会出现键盘闪现的情况 所以就修正UIAlertView http://blog.sina.com.cn/s/blog_ ...

  9. flask_sqlalchemy的使用

    第一配置文件 # coding:utf-8 DIALECT = 'mysql' DRIVER = 'pymysql' USERNAME = 'root' PASSWORD = ' HOST = '12 ...

  10. C. Ayoub and Lost Array(DP)

    (又是被队友带着上分的一场--) 题目链接:http://codeforces.com/contest/1105/problem/C 题目大意:给你n,l,r.每一个数都是在l,r范围之内,然后问你这 ...