D. AB-string

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

#include 
//#include 
//#include 
//#include 
//#include 

#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) ((x)&(-x))
#define mem(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define INF 0x3f3f3f3f
#define ll long long
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

const int mod=1e9+7;
const int N=1e6+9;


int main()
{
    FAST_IO;

    int n;
    cin>>n;
    string s;
    cin>>s;
    int pre=0;
    ll ans=((ll)n*(n-1)/2);
    for(int i=1;i=0;i--)
    {
        if(s[i]==s[i+1]) continue;
        ans-=(pre-i);
        pre=i;
    }
    cout<

 

你可能感兴趣的:(D. AB-string)