线段树单点更新,要注意两段合并多出的答案的计算即可
//============================================================================
// Name : D.cpp
// Author : L_Ecry
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include <iostream>
#define N 50050
using namespace std;
int value[N*];
char s[N];
inline int cal(int l,int r,int mid)
{ int res=;
if(mid>l&&s[mid-]=='w'&&s[mid]=='b'&&s[mid+]=='w')res++;
if(mid+<r&&s[mid]=='w'&&s[mid+]=='b'&&s[mid+]=='w')res++;
return res;
}
void build(int l,int r,int i)
{
if(l==r)
{
value[i]=;
return ;
}
int mid=(l+r)>>;
int lson=(i<<),rson=(i<<|);
build(l,mid,lson);
build(mid+,r,rson);
value[i]=value[lson]+value[rson]+cal(l,r,mid);
}
void update(int l,int r,int p,int i)
{
if(l==r)
{
return;
}
int mid=(l+r)>>;
int lson=(i<<),rson=(i<<|);
if(p<=mid)update(l,mid,p,lson);
else update(mid+,r,p,rson);
value[i]=value[lson]+value[rson]+cal(l,r,mid);
}
int query(int l,int r,int pl,int pr,int i)
{
if(l==pl&&r==pr)
{
return value[i];
}
int mid=(l+r)>>;
if(pr<=mid)return query(l,mid,pl,pr,i<<);
else if(pl>mid)return query(mid+,r,pl,pr,i<<|);
else
{
return query(l,mid,pl,mid,i<<)+query(mid+,r,mid+,pr,i<<|)+cal(pl,pr,mid);
}
}
int n,m;
void init()
{
scanf("%d%d",&n,&m);
scanf(" %s",s+);
build(,n,);
}
void solve()
{
while(m--)
{
int x,y,z;
char c;
scanf("%d%d",&x,&y);
if(x==)
{
scanf("%d",&z);
y++;z++;
printf("%d\n",query(,n,y,z,));
}
else
{
scanf(" %c",&c);
y++;
s[y]=c;
update(,n,y,);
}
}
}
int main() {
int tt,ri=;
scanf("%d",&tt);
while(tt--)
{
init();
printf("Case %d:\n",++ri);
solve();
}
return ;
}