站外题,不用调我的其他问题,把re调好就行(数据范围和一组数据放代码后面)
code:
#include <bits/stdc++.h>
using namespace std;
const int N=500010;
string s;
int n,m,to[N];
bool a[N];
signed main(){
// freopen("ball.in","r",stdin);
// freopen("ball.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>s[i];
if(s[i]=='/')
a[i]=1;
}
for(int i=1;i<=n;i++){
int tmp=i;
while(1){
if(a[tmp]==0){
if(tmp<=n-1&&a[tmp+1]==0)
tmp++;
else{
to[i]=tmp;
break;
}
}
else{
if(tmp>=2&&a[tmp-1])
tmp--;
else{
to[i]=tmp-1;
break;
}
}
}
}
while(m--){
int l,r;
cin>>l>>r;
for(int i=l;i<=r;i++)
a[i]=!a[i];
for(int i=l;i<=r;i++){
int tmp=i;
while(1){//man what can i say
if(a[tmp]==0){
if(tmp<=n-1&&a[tmp+1]==0)
tmp++;
else{
to[i]=tmp;
break;
}
}
else{
if(tmp>=2&&a[tmp-1]==1)
tmp--;
else{
to[i]=tmp-1;
break;
}
}
}
}
vector<int> tong(n+1);
for(int i=l;i<=r;i++)
tong[to[i]]++;
int ans=-1;
for(int i=0;i<=n;i++)
ans=max(ans,tong[i]);
cout<<ans<<endl;
}
return 0;
}
数据范围
n,m≤5000
RE的输入:here
玄一关