不清楚,只有wa,线段树
#include <bits/stdc++.h>
#define ls k<<1
#define rs k<<1|1
using namespace std;
const int N=5e5+5;
int n,q;
string s;
struct node{
int s,lm,rm,l,r;
}t[N*4];
node operator + (const node& l,const node& r){
bool cnt=(s[l.r]==s[r.l]);
return{
max(max(l.s,r.s),(cnt)*(l.rm+r.lm)),
max(l.lm,(cnt)*(l.s==l.r-l.l+1)*(l.s+r.lm)),
max(r.rm,(cnt)*(r.s==r.r-r.l+1)*(r.s+l.rm)),
l.l,
r.r
};
}
void pushup(int k){
t[k]=t[ls]+t[rs];
}
void build(int k,int l,int r){
t[k]={1,1,1,l,r};
if(l==r)return;
int mid=(l+r)/2;
build(ls,l,mid);
build(rs,mid+1,r);
pushup(k);
//cout<<l<<" "<<r<<" "<<t[k].s<<" "<<t[k].lm<<" "<<t[k].rm<<"\n";
}
void assign(int k,int l,int r,int a){
if(l==r)return;
int mid=(l+r)/2;
if(a<=mid)assign(ls,l,mid,a);
else assign(rs,mid+1,r,a);
pushup(k);
}
node query(int k,int l,int r,int a,int b){
if(a<=l&&r<=b)return t[k];
int mid=(l+r)/2;
node cntl={0,0,0,0,0},cntr={0,0,0,0,0},ans={0,0,0,0,0};
if(a<=mid)cntl=query(ls,l,mid,a,b);
else if(b>mid)cntr=query(rs,mid+1,r,a,b);
ans=cntl+cntr;
return ans;
}
int main(){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin>>n>>q>>s;
s=" "+s;
build(1,1,n);
while(q--){
int t,x;
cin>>t>>x;
if(t==1){
char y;
cin>>y;
s[x]=y;
assign(1,1,n,x);
}
else{
int y;
cin>>y;
cout<<query(1,1,n,x,y).s<<"\n";
}
}
}