| 比赛 |
26暑假集训模拟赛2 |
评测结果 |
AAAAAAAAAAA |
| 题目名称 |
It s Mooin Time III |
最终得分 |
100 |
| 用户昵称 |
exil |
运行时间 |
1.667 s |
| 代码语言 |
C++ |
内存使用 |
34.85 MiB |
| 提交时间 |
2026-07-02 09:35:13 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define int long long
int lshu[100005][28],rshu[100005][28];
char xu[27]={'0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
signed main(){
freopen("Time.in","r",stdin);
freopen("Time.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
string a;
cin>>a;
for(int i = 1;i<=26;i++){
int now=1;
int shang=1;
while(now<=n){
while(a[now-1]!=xu[i] && now<=n){
now++;
}
if(now>n)break;
for(int j = shang;j<=now;j++){
lshu[j][i]=now;
//cout<<j<<" "<<i<<" "<<now<<" "<<lshu[j][i]<<endl;
}
shang=now+1;
now++;
}
//cout<<shang<<endl;
for(int j = shang;j<=n;j++){
lshu[j][i]=-1;
}
}
for(int i = 1;i<=26;i++){
int now=n;
int shang=n;
while(now>=1){
while(a[now-1]!=xu[i] && now>=1){
now--;
}
if(now==0)break;
for(int j = now;j<=shang;j++){
rshu[j][i]=now;
//cout<<j<<" "<<i<<" "<<now<<" "<<lshu[j][i]<<endl;
}
shang=now-1;
now--;
}
//cout<<shang<<endl;
for(int j = 1;j<=shang;j++){
rshu[j][i]=-1;
}
}
for(int i = 1;i<=m;i++){
int l,r;
cin>>l>>r;
int ans=-1;
for(int i = 1;i<=26;i++){
//是否有该字母
if(lshu[l][i]==-1)continue;
//该字母是否跃出询问边界
if(lshu[l][i]>=r)continue;
int x=lshu[l][i];
for(int j = 1;j<=26;j++){
//该字母是否与字母i重合
if(i==j)continue;
//是否有该字母
if(rshu[r][j]==-1)continue;
//该字母是否跃出询问边界
if(rshu[r][j]<=l)continue;
//该字母位置是否在字母i后面
if(rshu[r][j]<=x)continue;
//这两个字母间距是否大于2
if((rshu[r][j]-x+1)<=2)continue;
int y=rshu[r][j];
int mid=(x+y)/2;
int mt=lshu[mid][j];
if(x<mt && mt<y){
ans=max(ans,(mt-x)*(y-mt));
}
mt=rshu[mid][j];
if(x<mt && mt<y){
ans=max(ans,(mt-x)*(y-mt));
}
}
}
cout<<ans<<endl;
}
return 0;
}