各位巨佬能帮忙看看,这个还有优化的空间吗?万分感谢各位QWQ
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9')f=ch=='-'?-1:1,ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-48,ch=getchar();
return x*f;
}
const int maxn=2e5+10;
int n,q;
int a[maxn];
int l[maxn];
int r[maxn];
int main(){
n=read(),q=read();
rep(i,1,q){
int x=read();
a[x]=(!a[x])?1:0;
cout<<"task "<<i<<":\n";
rep(j,2,n){
if(a[j-1]!=a[j]){
l[j]=l[j-1]+1;
}else{
l[j]=0;
}
}
per(j,n-1,1){
if(a[j+1]!=a[j]){
r[j]=r[j+1]+1;
}else{
r[j]=0;
}
}
int ans=0;
rep(i,1,n){
ans=max(ans,l[i]+r[i]+1);
}
cout<<ans<<endl<<endl;
}
return 0;
}